Page 1 of 1

Send a file via "put" command to a URL

Posted: Wed Apr 06, 2016 10:27 pm
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?

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

Posted: Thu Apr 07, 2016 12:15 am
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

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

Posted: Thu Apr 07, 2016 12:53 pm
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

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

Posted: Sun Apr 10, 2016 4:17 am
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.