Send a file via "put" command to a URL

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
pink
Posts: 285
Joined: Wed Mar 12, 2014 6:18 pm

Send a file via "put" command to a URL

Post by pink »

I am working on adding attachments to records in CouchDB.
I am trying to mimic the following command:

Code: Select all

curl -X PUT http://couch.mad.pink/test_suite_db2/zxsd3324d/bad_luck_friday13.jpg?rev=12-f5f9f6f0af4cb1f113c9794a10daf5bd \
    --data-binary /User/pink/Dropbox/bad_luck_friday13.jpg \
    -H "Cookie: AuthSession=cm9vdDo1NzA0NUVDRTovU5Y6gklEjt27Rn53KlC8TDQ4KQ" \
    -H "Content-Type: image/jpg"

Code: Select all

put "Cookie: AuthSession=cm9vdDo1NzA0NUVDRTovU5Y6gklEjt27Rn53KlC8TDQ4KQ"&cr&"Content-Type: image/jpg" into tHeader
set httpHeaders to tHeader
put "http://localhost/test_suite_db2/zxsd3324d/bad_luck_friday13.jpg?rev=12-f5f9f6f0af4cb1f113c9794a10daf5bd" into tURL

--TRY 1:
put "binfile:/User/pink/Dropbox/bad_luck_friday13.jpg" into tFilePath
put  URL(tFilePath) into URL(tURL)

--TRY 2:
put  URL ("binfile:/User/pink/Dropbox/bad_luck_friday13.jpg") into tFile
put  tFile into URL(tURL)
in both of the above attempts, the file is successfully created at the server, however it is empty

Can anyone suggest another approach?
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know
Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Send a file via "put" command to a URL

Post by Simon »

Hi Greg,
I don't know about CouchDB but I load the img into a card then

Code: Select all

 put the text of img "Image_Test" into tImg
 put base64encode (tImg) into gImageData
and upload gImageData.

Works with mySQL. Oh, I guess I never tried blob.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
pink
Posts: 285
Joined: Wed Mar 12, 2014 6:18 pm

Re: Send a file via "put" command to a URL

Post by pink »

unfortunately that won't work because CouchDB also works as an http server, image files need to stay images or they won't display
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know
pink
Posts: 285
Joined: Wed Mar 12, 2014 6:18 pm

Re: Send a file via "put" command to a URL

Post by pink »

well, after working on this for way too long I have discovered that the following does indeed work:

Code: Select all

put "binfile:/Users/pink/Dropbox/bad_luck_friday13.jpg" into tFilePath
put  URL(tFilePath) into URL(tURL)
Shamefully I have to admit that the problem all this time was a typo in my file path.
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know
Post Reply