This is a migrated thread and some comments may be shown as answers.

Download file from another provide inside Cloud Code

5 Answers 59 Views
Cloud Code
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Viktor
Top achievements
Rank 1
Viktor asked on 13 Sep 2017, 03:09 PM

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

Sort by
0
Martin
Telerik team
answered on 15 Sep 2017, 02:15 PM

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
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Viktor
Top achievements
Rank 1
answered on 15 Sep 2017, 03:57 PM

Hi Martin,

Is it possible to download it with Everlive.Http and use some Buffer, then encode to base64  and then save it?

 

Thanks

0
Martin
Telerik team
answered on 18 Sep 2017, 02:52 PM

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
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Viktor
Top achievements
Rank 1
answered on 19 Sep 2017, 07:42 AM

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,

0
Martin
Telerik team
answered on 20 Sep 2017, 10:54 AM

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
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
Cloud Code
Asked by
Viktor
Top achievements
Rank 1
Answers by
Martin
Telerik team
Viktor
Top achievements
Rank 1
Share this question
or