How to upload picture and save picture in the documents

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
lemodizon
Posts: 175
Joined: Thu Apr 05, 2018 3:33 pm

How to upload picture and save picture in the documents

Post by lemodizon » Fri Jul 02, 2021 5:55 am

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
Attachments
Capture.JPG
Thank you & God Bless Everyone :wink:

Regards,
lemodizon

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Fri Jul 02, 2021 8:44 am

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

lemodizon
Posts: 175
Joined: Thu Apr 05, 2018 3:33 pm

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

Post by lemodizon » Sat Jul 03, 2021 4:27 am

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.
Thank you & God Bless Everyone :wink:

Regards,
lemodizon

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

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

Post by jmburnod » Sat Jul 03, 2021 9:18 am

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
https://alternatic.ch

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Sat Jul 03, 2021 1:14 pm

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

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

Post by jmburnod » Sat Jul 03, 2021 1:42 pm

Hi Klaus,
Works now like a charm here
Best
Jean-Marc
https://alternatic.ch

lemodizon
Posts: 175
Joined: Thu Apr 05, 2018 3:33 pm

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

Post by lemodizon » Sun Jul 04, 2021 9:47 am

Hi Klaus,

Thanks :) . this is now working.
Thank you & God Bless Everyone :wink:

Regards,
lemodizon

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”