mobilePickPhoto Save the Photo

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
JereMiami
Posts: 122
Joined: Mon Nov 03, 2014 12:17 am

mobilePickPhoto Save the Photo

Post by JereMiami » Tue Jan 19, 2021 2:59 am

After picking the photo from the android album or library, how do you save it to specialFolderPath("resources") or a subfolder therein, such as "images?"

What am I missing here ...

Code: Select all

if the environment is "mobile" then
      mobilepickPhoto "album"
      if the result <> EMPTY then
         answer "Error:" && the result
         exit mouseup
      end if
      put the text of last image into tData
      put base64encode(tData) into tBase
      set the text of img "customPhoto" of grp "pickPhoto" to tData
      set the defaultFolder to specialFolderPath("resources")
      put last image into url ("binfile:" & "sample.jpg")
      set the vis of grc "background" of grp "pickPhoto" to false
      set the vis of fld "field" of grp "pickPhoto" to false
      set the vis of img "customPhoto" of grp "pickPhoto" to true
      delete last img
 end if 

SparkOut
Posts: 2894
Joined: Sun Sep 23, 2007 4:58 pm

Re: mobilePickPhoto Save the Photo

Post by SparkOut » Tue Jan 19, 2021 8:41 am

The short answer, specialFolderPath("resources") is read only.
On mobile, you will need to write to specialFolderPath("documents") instead.
If necessary, "resources" bundled with the standalone builder will need to be copied to "documents" on first run of the app.

JereMiami
Posts: 122
Joined: Mon Nov 03, 2014 12:17 am

Re: mobilePickPhoto Save the Photo

Post by JereMiami » Tue Jan 19, 2021 3:20 pm

Correct. Thanks so much. I totally forgot that it was read only. The following code successfully: (1) allows the user to select from the mobile album; (2) places the jpg image into an image object on the card; and (3) saves the image to the specialFolderPath("documents") folder in the standalone sandbox, where it can be uploaded to a server, and I have tested that the jpeg is received intact.

Thanks- It was driving me nuts.

Code: Select all

on mouseUp
   if the environment is "mobile" then
      mobilepickPhoto "album"
      if the result <> EMPTY then
         answer "Error:" && the result
         exit mouseup
      end if
      put the text of last image into tData
      put base64encode(tData) into tBase
      set the text of img "customPhoto" of grp "pickPhoto" to tData
      set the defaultFolder to specialFolderPath("documents")
      put last image into url ("binfile:" & "photo.jpg")
      set the vis of grc "background" of grp "pickPhoto" to false
      set the vis of fld "field" of grp "pickPhoto" to false
      set the vis of img "customPhoto" of grp "pickPhoto" to true
      put specialFolderPath("documents") & "/photo.jpg" into tPath
      delete last img
   end if
end mouseUp

Post Reply

Return to “Android Deployment”