Page 1 of 1

How to upload picture and save picture in the documents

Posted: Fri Jul 02, 2021 5:55 am
by lemodizon
Hi Everyone,

I tried to create a stack where I can upload image and save it automatic in the documents of my computer. And if i want it to edit the filename and it should display the right picture how do we do it in livecode. hope you can guide me. Thanks in advance

step 1. Browse a picture here is my code below

Code: Select all

on mouseUp
   set the cursor to watch
   answer file "Please select an image file for your product." with \
         type "All Images|jpg,jpeg,gif,png|JPEG,GIFf,PNGf" or \
         type "JPEG Images|jgp,jpeg|JPEG" or \
         type "GIF Images|gif|GIFf" or \
         type "PNG Images|png|PNGf"
   put it into tImagePath
   set the filename of image "ItemImg" to tImagePath
   
end mouseUp
step 2. enter the filename in the field.

step 3. once clicked it will automatic saved in the documents with filename i entered. but I don't know on how to change the filename i set in my code here is my code below

Code: Select all

on mouseUp

   put fld "filenameFld" into myFileName
   put ("binfile:" & specialFolderPath("Documents") & "/logo.jpg") into theFolder
   export img "ItemImg" to URL theFolder as JPEG
   answer "Done" 
   
end mouseUp

Re: How to upload picture and save picture in the documents

Posted: Fri Jul 02, 2021 8:44 am
by Klaus
Hi lemodizon,

do this:

Code: Select all

on mouseUp
   put fld "filenameFld" into myFileName
   put (specialFolderPath("documents") & "/" & myFileName & ".jpg") into theFolder
   export img "ItemImg" to URL theFolder as JPEG
   answer "Done"  
end mouseUp
Hints:
1. iOS and Android are case sensitive OS, so we must not use capitals -> documents NOT Documents!
2. Here we just create a filename from the field and the suffix .jpg (if neccessary)
3. Don't use BINFILE or FILE here, this is just a string that is passed to the EXPORT command.


Best

Klaus

Re: How to upload picture and save picture in the documents

Posted: Sat Jul 03, 2021 4:27 am
by lemodizon
Hi Klaus,

This is noted. Thanks for the hints. I tried the code (no error found) but there is no export image file in my documents of my computer.

Re: How to upload picture and save picture in the documents

Posted: Sat Jul 03, 2021 9:18 am
by jmburnod
Hi,
I tested script of Klaus. I tried it with referenced control and as control (i thought that is not possible with a referenced file).
Both doesnt' work here (OS X 10.14.6, LC 9.6.1) without error message. :shock:

Code: Select all

answer (there is a file theFolder)
return false

Kind regards
Jean-Marc

Re: How to upload picture and save picture in the documents

Posted: Sat Jul 03, 2021 1:14 pm
by Klaus
Hi all,

sorry, my fault, it has to read FILE not url!

Code: Select all

on mouseUp
   put fld "filenameFld" into myFileName
   put (specialFolderPath("documents") & "/" & myFileName & ".jpg") into theFolder
   export img "ItemImg" to FILE theFolder as JPEG
   answer "Done"  
end mouseUp
Best

Klaus

Re: How to upload picture and save picture in the documents

Posted: Sat Jul 03, 2021 1:42 pm
by jmburnod
Hi Klaus,
Works now like a charm here
Best
Jean-Marc

Re: How to upload picture and save picture in the documents

Posted: Sun Jul 04, 2021 9:47 am
by lemodizon
Hi Klaus,

Thanks :) . this is now working.