Reading and Converting JPEG image to String from SD Card Arduino Yun

I am trying to use the command

Process firebase;
firebase.runShellCommand("curl -k -X PATCH -d @</mnt/sda1/text.txt> https://shms.firebaseio.com/image.json ");

while(firebase.running());

in the Arduino environment to upload to Firebase but it is failing to do so. I have replaced PATCH with PUT in your code because PUT deletes all parent fields in the firebase. What am I doing wrong?

firebase.runShellCommand("curl -k -X PATCH -d @</mnt/sda1/text.txt> https://shms.firebaseio.com/image.json ");

Does this command work if you run it from ssh?

No, I get the error "-ash: can't create https://shms.firebaseio.com/image.json: non existent directory". What is the proper way of doing this?

I don't know :smiley: But that is useful to see if the problem is in your sketch or the way you call curl. Try via ssh or directly on your computer to find a working curl command and then use it in your sketch.

might try this?

[s]curl -k -X PATCH -d @'/mnt/sda1/text.txt' 'https://shms.firebaseio.com/image.json' [/s]
cd /mnt/sda1
wget https://lh3.googleusercontent.com/-XW1x_JT1g24/AAAAAAAAAAI/AAAAAAAAACs/_IO1-fwpWTE/photo.jpg --no-check-certificate
nano /mnt/sda1/uploadimage.sh
#!/bin/ash
strbase64=$(/usr/bin/base64 --wrap=0 /mnt/sda1/photo.jpg)
strjason="{\"image\":\""+$strbase64+"\"}"
#echo $strjason
curl -k -X PATCH -d $strjason  'https://shms.firebaseio.com/image.json'
chmod 755 /mnt/sda1/uploadimage.sh
/mnt/sda1/uploadimage.sh

browser "https://shms.firebaseio.com/image.json" to view.

It worked at first but in the following trials I got the error "Invalid data; couldn't parse JSON object. I have figured out the problem.

#!/bin/ash
strbase64=$(/usr/bin/base64 --wrap=0 /mnt/sda1/photo.jpg)
strjason="{"image":""+$strbase64+""}"
#echo $strjason
curl -k -X PATCH -d $strjason 'https://shms.firebaseio.com/image.json'

the $ sign in front of strjason in the last line of the code is causing an error at the Firebase side. How can I manipulate the variable $strjason so that I can upload the same content but without having a $ sign in the curl method?

Edit: I have noticed that when I upload 320x240 images the code just works fine but gives the error above when I try it with 640x480. I believe that it is the result of $ sign again although I may be mistaken.

If I were you, I drop a line to firebase to ask max size for json string while use PATCH. or if it support other type file format.

yagiz23:
I am trying to use the command

Process firebase;

firebase.runShellCommand("curl -k -X PATCH -d @</mnt/sda1/text.txt> https://shms.firebaseio.com/image.json ");

while(firebase.running());




in the Arduino environment to upload to Firebase but it is failing to do so. I have replaced PATCH with PUT in your code because PUT deletes all parent fields in the firebase. What am I doing wrong?

@yagiz23,
simple enough.

you wrote:
https://shms.firebaseio.com/image.json

I wrote:
https://<nm>.firebaseio.com/[b]images/[/b]image.json

While it is possible to do the former, firebase really wants things stored further down in the tree. In addition, storing things in such a shallow manner makes it hard to change and add things in the future. True, this is something that needs experience, but it should work work you.

To be clear, the extra path component is not need, but it makes the work a lot easier.

You should also read the firebase REST API. FWIW, you likely wasted an hour, by not reading it.
I Guess I just wasted time.

Give it a try.
Jesse

sonnyyu:
If I were you, I drop a line to firebase to ask max size for json string PATCH.

Not need. Max size for anything is 10Megabytes. OP not reading documentation.
Correction, I made a mistake.

Jesse

Found the problem.

curl -V
curl 7.29.0 (mips-openwrt-linux-gnu) libcurl/7.29.0 OpenSSL/1.0.1h zlib/1.2.7
Protocols: file ftp ftps http https imap imaps pop3 pop3s rtsp smtp smtps tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP

curl 7.29.0 (mips-openwrt-linux-gnu) has limit at string size we pass it and does not report error if over limit.

cd /mnt/sda1/
wget -O uno.jpg http://www.adafruit.com/images/970x728/50-01.jpg

size of uno.jpg:970*728

Revision of code ( should support up to 10MB):

nano /mnt/sda1/upload.sh
#!/bin/ash
strbase64=$(/usr/bin/base64 --wrap=0 /mnt/sda1/uno.jpg)
echo "{\"image\":\""+$strbase64+"\"}" > /mnt/sda1/test.base64
curl -k -X PATCH  -d @/mnt/sda1/test.base64   'https://shms.firebaseio.com/images/image.json'
chmod 755  /mnt/sda1/upload.sh
 /mnt/sda1/upload.sh

Hide standard and error outputs:

curl -k  -X PATCH  -d @/mnt/sda1/test.base64 'https://shms.firebaseio.com/images/image.json' > /dev/null 2>&1

@yagiz23,
Sorry, I just noticed a major mistake in my previous post. I have added to that post and am now repeating here.

Jesse

Generically, here is you call:

$ curl -X PUT -d @<filename_of_base64text> https://.firebase.io.com/images/.json

At this point, all you need to do is replace the items in between the angle brackets "<>".

START NEW
Okay. One problem, that even I forgot, is that firebase wants to see everything as JSON. That means you will need to modify the base64 file. Basically double quote the label and the value and wrap it in curly braces. Like this:

{"image":"iVBORw0KGgoAAAA....kJggg=="}

I'm sorry I forgot to mention this earlier. I've been bouncing back and forth between, the YUN, my blog and phonegap stuff.... I just forgot this. Sorry again.

END NEW
I hope this is clears things up. I have tested on my laptop, and in a few minutes I will test this on my Yun. If not, please ask more questions.

Okay. I made a mistake here. I'll get you the correct call in a bit. 8:15pm local time
Okay, I've added new information that should fix the problem. 8:55pm

Jesse

@yagiz23,

Okay. I just ran the test on my Yun. It works. There was on small difference. Because I have an SSL issue, the -k option must be used. So it looks like this

curl [b]-k[/b] -X PUT -d @AY https://<your-subdomain>.firebaseio.com/images/image.json

Sorry for the problems and mistake from before.

Lastly, if this solves your issues, please append [SOLVED] to the subject line, and also mention firebase in the subject line.

Jesse