Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] File_url parameter is optional but it says mandatory field. #53

Open
Abhishekranjan56 opened this issue Mar 11, 2024 · 8 comments
Assignees

Comments

@Abhishekranjan56
Copy link

When Up Uploading a file from local storage it shows file_url is mandatory.

The Error logged :-
{"_server_messages": "["{\"message\": \"Fields file_name or file_url must be set for File\", \"title\": \"Message\", \"indicator\": \"red\", \"raise_exception\": 1, \"__frappe_exc_id\": \"edfbf39cb7c6aa07fd6c67fcbaadbc703635505b7b87ff1571247742\"}"]", "exc_type": "MandatoryError", "exception": "", "httpStatus": 417, "httpStatusText": undefined, "message": "There was an error while uploading the file."}

fileName>>>>> 820b6003-d080-4e81-ac44-afcc909aaf96.png
Payload :- const fileArgs = {
isPrivate: true,
folder: "Home",
file_name: fileName,
doctype: "User",
docname: "sub doc type",
fieldname: "user_image"
};
file
.uploadFile(myFile, fileArgs, (completedBytes, totalBytes) =>
console.log(Math.round((completedBytes / totalBytes) * 100), " completed")
)
.then((r) => console.log(r))
.catch((e) => console.error(e));

@nikkothari22
Copy link
Member

nikkothari22 commented Mar 11, 2024

@Abhishekranjan56 Which version are you using?
Also, you do not need to pass in the "file_name" either if you are uploading a File object.

@Abhishekranjan56
Copy link
Author

I am using "frappe-js-sdk": "^1.4.3", and if I am not passing the file_name it doesnot matter it still shows same error.
{"_server_messages": "["{\"message\": \"Fields file_name or file_url must be set for File\", \"title\": \"Message\", \"indicator\": \"red\", \"raise_exception\": 1, \"__frappe_exc_id\": \"9939bee13b0e544363299709426c69a0af0b249b360be674854890bc\"}"]", "exc_type": "MandatoryError", "exception": "", "httpStatus": 417, "httpStatusText": undefined, "message": "There was an error while uploading the file."}
still shows this error with
const fileArgs = {
isPrivate: true,
folder: "Home",
doctype: "User",
docname: "sub_doc_name",
fieldname: "user_image"
};
with this payload

@nikkothari22
Copy link
Member

Can you clear your node modules and .lock file and install all the dependencies again? I am not able to reproduce it on our end. We were facing some issues earlier, but that was fixed in v1.4.3

@Abhishekranjan56
Copy link
Author

Can you clear your node modules and .lock file and install all the dependencies again? I am not able to reproduce it on our end. We were facing some issues earlier, but that was fixed in v1.4.3

Sure
Will test and Update.

@Abhishekranjan56
Copy link
Author

Abhishekranjan56 commented Mar 11, 2024

Done that but same error still persist. Is file_url prop is mandatory??

@Abhishekranjan56
Copy link
Author

Abhishekranjan56 commented Mar 14, 2024

This is the sample of file object I am sending :-
file:///data/user/0/com.abhishekapp.dev/cache/ImagePicker/f321fbf2-ddec-4bda-bffe-8b57bd1e8289.png
it is the local path of image I want to attach to frappe dashboard using expo image picker.
The Error produced is :-
{"_server_messages": "["{\"message\": \"Fields file_name or file_url must be set for File\", \"title\": \"Message\", \"indicator\": \"red\", \"raise_exception\": 1, \"__frappe_exc_id\": \"77f2ed88f2a9dabbafa15525f96885d980419b34b58234b6cb1a724d\"}"]", "exc_type": "MandatoryError", "exception": "", "httpStatus": 417, "httpStatusText": undefined, "message": "There was an error while uploading the file."}
@nikkothari22

@nikkothari22
Copy link
Member

Oh okay. I didn't know you were using Expo (RN). I haven't tried it on Expo myself, but I know Hussain has an example of a file upload function in doppio_mobile. You won't be able to use the inbuilt function here for raw file uploads but we plan on adding support for that in frappe-JS-SDK and frappe-react-SDK

@sambhusbabu
Copy link

sambhusbabu commented Sep 4, 2024

In my case, I use this code in my React Native and this error resolved

const pictureData = { name: photo.fileName, type: photo.type, uri: photo.uri, };
Make a data like this in your project and pass this data to image file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants