How to save an image from a given URL

Hi all,

I am new to mobile app development.

I want to download an image from web and save in mobile device (currently Android). I read a lot post and try some plugin. but I still get an unknown error.

I use the DownloadFile function from FileTransferPlugin, Here is the error I get


and This is my Code, I'm sure the action run into the "DownloadFile2" Function correctly


Here is the image link 

SyntaxEditor Code Snippet

"http://images2.gamme.com.tw/news2/2017/03/63/q5iZop2elKCXsKQ.jpg"

and the FileSystemURL

SyntaxEditor Code Snippet

 "/??????/DCIM/ME/abc.jpg"


I suspect the File SystemURL is wrong, I stuck on these for a day, can anyone give me some guideline, thank you. 

sb chung wrote:

Hi all,

I am new to mobile app development.

I want to download an image from web and save in mobile device (currently Android). I read a lot post and try some plugin. but I still get an unknown error.

I use the DownloadFile function from FileTransferPlugin, Here is the error I get


and This is my Code, I'm sure the action run into the "DownloadFile2" Function correctly


Here is the image link 

SyntaxEditor Code Snippet

"http://images2.gamme.com.tw/news2/2017/03/63/q5iZop2elKCXsKQ.jpg"

and the FileSystemURL

SyntaxEditor Code Snippet

 "/??????/DCIM/ME/abc.jpg"


I suspect the File SystemURL is wrong, I stuck on these for a day, can anyone give me some guideline, thank you. 

And I try a lot of different FileSystemURL as well, but still can't success


Hi, 

Is there any error log in Service Center? This would help understand the problem. 

In any case, does your application has permission to use the file system of the device? There is a plugin in Forge to deal with permissions. 

Also, where are you testing this? If in Browser, I suspect it will not work; plugins that deal with the device do not work on browser, and only a few work on OutSystems Now. 

Cheers 

Hi,


Try using file system url as

"/storage/emulated/0/test"


As I understand the download file does not understand special characters.


Regards,

Saugat

Eduardo Jauch wrote:

Hi, 

Is there any error log in Service Center? This would help understand the problem. 

In any case, does your application has permission to use the file system of the device? There is a plugin in Forge to deal with permissions. 

Also, where are you testing this? If in Browser, I suspect it will not work; plugins that deal with the device do not work on browser, and only a few work on OutSystems Now. 

Cheers 


Hi, Here is the log in service center, these two errors occur repeatedly, I don't know what it means.

1. I use the "CheckAndroidPermissionsPlugin" to ensure the app have the "Entities.AndroidPermission.WRITE_EXTERNAL_STORAGE" right. and I have double check the system setting to give the write permission right to the app. Is this the same as "permission to use the file system of the device"

2. I run the app in my mobile phone (Android)

Thank you




Saugat Biswas wrote:

Hi,


Try using file system url as

"/storage/emulated/0/test"


As I understand the download file does not understand special characters.


Regards,

Saugat


I tried, but still cannot save the image, same error message.

Should I create the folder in mobile phone first? If yes, where should I find the "/storage/"? I know how to open the file explorer and go to internal / external storage, but I don't know where to navigate to? same as internal storage?

Sorry, I'm super new to mobile app development. Seems saving a file to the device should be a simple stuff...

Hi, 

Saving to mobile is not simple because of the permissions settings... Mobiles are very annoying, but with reason. 

Two questions. 

First, are you testing this in the device? This will not work on chrome or OutSystems Now app. You need to install the app on device to test. 

Second, are you sure you are testing the right permission? Or setting the right permission? I think the phone storage and external storage (card) are different things... 

P. S. 

Another thing. 

After adding the plugin, did you generated a new package and installed the app again on the device? 

Generating a new package and installing again (or updating from store if installed from there) is mandatory when adding plugins that contain native code, as it is the case. 

Cheers 

Eduardo Jauch wrote:

Hi, 

Saving to mobile is not simple because of the permissions settings... Mobiles are very annoying, but with reason. 

Two questions. 

First, are you testing this in the device? This will not work on chrome or OutSystems Now app. You need to install the app on device to test. 

Second, are you sure you are testing the right permission? Or setting the right permission? I think the phone storage and external storage (card) are different things... 

Thank you Eduardo,


Yes, I'm testing it in my mobile phone. Samsung S7.

Yes, I have regenerate the application. But this time i don't know why the Outsystems Studio ask me to sign the application. I sign it and reinstalled in my mobile phone. everything run as expected (expect the download)

and Yes again, I think I have give the write permission. Here is the screen cap of the application permission.


I'm following the Mobile app course to create this ToDo_App1. and I added a page with button to implement the download function.
the ToDo_App1 is ok to update the local entity (I follow the instruction of the course, everything works fine), so I suppose the ToDo_App1 has the permission to write in internal storage? and I can't find any other setting can grant the local write permission explicitly.


Here are two questions I would like to ask, please give me some direction to try:

1. Is there any file path which can explicitly to tell the FileTransferPlugin to save file in SD card? and I notice that there are URI and URL (I don't know the difference), is the path  "/storage/emulated/0/test/abc.jpg" a correct format to pass to the function?


2. I am able to use postman to get the image of the same URL address. I add artoHttp plugin and try to use the get method to obtain the picture. But the response of the body is "Text", is there any function / command to convert the response body to image?


Thank you very much :) 

sb chung wrote:

Saugat Biswas wrote:

Hi,


Try using file system url as

"/storage/emulated/0/test"


As I understand the download file does not understand special characters.


Regards,

Saugat


I tried, but still cannot save the image, same error message.

Should I create the folder in mobile phone first? If yes, where should I find the "/storage/"? I know how to open the file explorer and go to internal / external storage, but I don't know where to navigate to? same as internal storage?

Sorry, I'm super new to mobile app development. Seems saving a file to the device should be a simple stuff...

The path /storage/emulated/0/test was just an example, and the path varies with different devices.

You can use the file plugin (https://www.outsystems.com/forge/component-versions/1633) to get the storage path for downloading files.


Regards,

Saugat