Hello Frappe Community,
I am facing an issue with file uploads in the Job Application form of my Frappe application. Specifically, I am encountering a ‘PermissionError’ when attempting to use the ‘upload_file’ method.
Here’s what I’ve done so far:
- Granted ‘Read’, ‘Write’, and ‘Create’ permissions to the “Job Applicant” role.
- Tried adjusting role permissions in the Role Permissions Manager.
However, the error persists. Additionally, I have noticed that file uploads work correctly when a user is logged in, but the issue arises when a user is logged out.
Could anyone please guide me on the correct way to grant permissions for the ‘upload_file’ method? Any insights or experiences shared would be greatly appreciated.
let makecall = async()=>{
let formdata = $('#jobapply').serializeArray().reduce(
(obj, item)=>(obj[item.name]=item.value, obj), {}
);
let filedata = $('#jaFile')[0].files[0];
// initialize form
fileprivate = 1
let fileContent = new FormData()
if(filedata){
fileContent.append('file', filedata);
fileContent.append('is_private',fileprivate);
}
// end initialize
// post to API
if(formdata){
let res = await $.ajax({
url: '/api/resource/Job Applicant',
type: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Frappe-CSRF-Token': frappe.csrf_token
},
data: JSON.stringify(formdata),
success: function(data){
return data;
},
error: function(data){
return data;
}
});
console.log(res);
// upload image
if(res.data && filedata){
let fileres = await fetch('/api/method/upload_file', {
headers: {
'X-Frappe-CSRF-Token': frappe.csrf_token
},
method: 'POST',
body: fileContent
})
.then(res=>res.json())
.then(data=>{
console.log(data);
// finally update document
if(data.message){
// update agent
$.ajax({
url: `/api/resource/Job Applicant/${res.data.name}`,
type: 'PUT',
headers: {
'Content-Type': 'application/json',
'X-Frappe-CSRF-Token': frappe.csrf_token
},
data: JSON.stringify({resume_attachment:data.message.file_url}),
success: function(data){
showPopup();
return data
},
error: function(data){
return data
}
})
// end update agent
}
})
}
}
}
error occur in this line
fetch('/api/method/upload_file'
Error:
{exception: 'frappe.exceptions.PermissionError', exc: '["Traceback (most recent call last):\\n File \\"app…ssionError\\nfrappe.exceptions.PermissionError\\n"]'}
Thank you in advance for your help!