VaRest
VaRest copied to clipboard
Upload image/file helper function
How to upload file (a csv file) along with other string data? For example, send data: name (string), id (string), and file (csv) to server
It's not possible for now, but I'll take a look for upcoming release.
That would be great. I need it too. :)
An ImageToByteArray function might do the job, as there is already a Base64Encode function for byte arrays in unreal. Base64 can be then uploaded as regular text and decoded server side. Not super efficient for frequent uploading but should do in most cases and would work with any byte arrays/files (not just images).
any progress for file uploading?
This is how I upload files with VaRest:
@Minas314 Can you please tell what is under the hood in the node "Read bytes from file"? I wanted to try your method of uploading files, but I'm stack on converting file to byte array.
@kasp1 the same question, can you please guide a little about suggested ImageToByteArray function?
My case is - I make request to some API and the response is just one image in .png format. How can I process this response for further usage of this .png file.
@IlliaImm If you develop the API as well then you would server the image as a Base64 encoded string, which you would download using a VaRest request and then use the Base64 decode function to turn it into a byte array, which you could then convert to a texture
If the image is presented as the image (already a byte array) you could use this unreal engine core function to turn it into a texture: https://docs.unrealengine.com/4.26/en-US/BlueprintAPI/Class/AsyncTaskDownloadImage/DownloadImage/
@kasp1 Thank you for the response!
No, the API that I'm trying to communicate with is from some service provider, so I can't do anything with it's server side.
I tried that you recommended, but didn't succeeded in converting/decoding the response to smth that I can use. I attached screenshots to show what I get as a response and how I tried to decode it(i also tried without splitting the string - same result). And I'm not sure how I can use "DownloadImage" node, cause it requires simple URL. But my request consists not only of url, it also has a json object as a payload.
Hope you can help.
Screenshots
@IlliaImm Nope, looks like you are trying to Base64 decode the actual image, which won't work because the image is not base64 encoded but raw image data already.
If I understand your case correctly, you need something like this:
...or even better get the response content as a byte array right away if that's possible?
Tip: You should be able to use the response Content-Type header to figure out if the content is png image (if the value of this header equals "image/png".
@kasp1 Really appreciate your help. Sorry for bothering you many times.
Unfortunately, there is no option to get response content as a byte array. And unfortunately there is no unreal built-in function StringToByteArray. Also I checked if I can ask this API for some other types of data and the variants are only image/png (object) or image/jpeg (object) or image/tiff (object).
As you pointed in tip, I checked Content-Type and yes, it's image/png. So for now I didn't make it work for me. I will look for some other options and if I will find a working solution I'll post it here. I'm wondering if there is a possibility to just save response content as file in game directory and then just try to use this file? If you have some other suggestions I would really like to try it.
Thank you again.
Maybe this function could be wrapped into a custom blueprint function and used in blueprints https://docs.unrealengine.com/4.26/en-US/API/Runtime/Core/Containers/StringToBytes/
I found solution that worked for me. I tried some different plugin that provides Byte Data of the response. And this Byte Data could be easily converted to a Texture by built-in function ImportBufferAsTexture2D.
So it would be really nice to have in VaRest plugin a possibility to get Byte Data of the response and also a possibility to save it as a file in project directory.
Hi is it possible to send form-data using VARest like use the request object and binary contents with files value.
Hi! I make it work by using this way in UE5, Base64 to Texture2D
@chase03 Thanks i actually need to push to server, using multi-part form. And not read it. If you have been able to puch it let me know the data field is of type json and files.audioresponse is a binary file.
This is how I upload files with VaRest:
So far I don't understand where you get that function from called "Read Bytes from File", VArest doesn't have it, nor is there a code in this thread to do it in c++