-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
How to use this for binary file uploads #881
Comments
I assume that your file content is stored as a string in the JSON object. The library stores it as std::string &ref = js["body"].get_ref<std::string&>(); Then you can do whatever you would have done with a However, please note the library assumes UTF-8 encoded strings. If the parser or serializer encounters invalid UTF-8 byte sequences, it will throw an exception. |
I did that but as you see
and
which are different. Do I need to send my binary file as a base64 encoded string from the front end to save it properly? |
Oh, now I understand. If you pass a JSON value to a stream like So |
Any news on this? |
Hey sorry forgot to update this.....figured it out....to enable file uploads and downloads had to convert binary file into base64 encoded string before sending the json from frontend...and back to base64 decode when user wants to download it again Marking it as close Thanks for your help |
untitled.zip
I am writing a code where the front end sends a file within a json object
I have file in js["body"] the contents of the file.
I also have the size of the file in js["size"]
where js is the json object as
body is the file content and size is the size of the file in bytes
On printing js["body"] the file contents are correct.
Now I need to send this file via socket to another service.
For that I tried stringifying it, memcpy into char* buffer, memcpy in void* buffer but none seems to work correctly.
What is the correct method to copy js["body"] byte by byte into a char*, so that I may send it over a socket to another service which saves it as a actual file.
How do I do that?
sample code I am using
Output I am getting is
Only the first output is correct in this case which I am getting by directly printing js["body"]
Any pointers would be highly appreciated.
ENVIRONMENT
OS : ubuntu 16.04
COMPILER : g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
ATTACHED is the binary file within the zip which I am uploading.
Thanks
The text was updated successfully, but these errors were encountered: