Hi guys,
Is it possible to download a file from a URL inside the Cloud Code?
The scenario is that I'm receiving an URL of an image from Facebook and I would like to store it in Backend Services.
If that is possible, could you provide sample?
Thanks
5 Answers, 1 is accepted
Hi Viktor,
Uploading and downloading of files is not supported in Cloud code using the JavaScript SDK as the SDK is using File Transfer plugin which is not available in cloud code. Using the Everlive.Http module would also not work as has some limitations as well.
Therefore you would have to download the file to the device and then upload it to the backend.
I hope this has helped.
Regards,Martin
Progress Telerik
Hi Martin,
Is it possible to download it with Everlive.Http and use some Buffer, then encode to base64 and then save it?
Thanks
Hi Viktor,
Indeed using the Buffer module and uploading the file as Base64 would be the only possible option as sending request with multipart/form-data is not supported in cloud code.
I have considered this approach as well - still, the response from the Everlive.Http request when downloading the file to cloud code would come not as a Buffer but would be encoded as string. Later, when converting the string to Buffer leads to corrupted file from what I have tested.
In general cloud code was never designed to support download and upload of files. Furthermore, as the image gets bigger, the time for downloading, converting to Base64 and uploading the file would increase as is the chance to hit the set maximum execution time of the cloud function of 10 seconds.
Therefore, given the current limitations in cloud code, I believe the best/most robust solution would be to download/upload the file through the device and not use cloud code
Could you please share some more details on your exact use case - would you trigger the request from the device or a server? If so, then I assume you are trying to save the upload bandwidth (as you would have to download and store the image on the device at some point).
I am asking this in order for us to be able to review and propose what would be the best solution in your use case.
Let me know what you think.
Regards,Martin
Progress Telerik
Hi,
My scenario is that I'm building a chatbot for Messenger. This chatbot collects some data from the user and one of the things is an image. Then all the data is sent to Backend Services to be handled. I receive the image as URL to Facebook's CDN. I would like to store the images here. Facebook URLs expire at some point of time.
The images, after they are processed from FB, are relatively small (<1MB).
Thanks,
Hi Viktor,
Thank you for specifying your use case. We have reviewed it and have tried several approaches with the existing functionality. Still, for now, I would have to confirm that Cloud code functionality does not support downloading of files. You would have to download the file on your application server and then upload it to Backend services.
Let me know if you have further questions.
Regards,Martin
Progress Telerik