Can CDNs handle base64 encoded data? - image-processing

I'm trying to make an app where I take pictures from users add them to a canvas, draw stuff in them, then convert them to a base64 string and upload them.
For this purpose I'm considering the possibility to use a cdn but can't find information on what I can upload to them and how the client side uploading works. I'd like to be able to send the image as base64 and the name to be given to the file, so that when it arrives to the origin cdn, the base64 image is decoded and saved under the specified name (which I will add to the database on the server).Is this possible?Can I have some kind of save.php file on the origin cdn where I write my logic to save the file and to which I'll send XHR requests? Or how this whole thing work?I know this question may sound trivial but I'm looking for it for hours and still didn't find anything which explains in detail how the client side uploading work for CDNs.

CDNs usually do not provide such uploading service for client side, so you can not do it in this way.

Related

how to send image in messaging xmpp framework?

I'm sending only text, but I don't know how to send image/url, videos and integrate that in the chat application in iOS using XMPP.
I have refer so many questions but I want to send image using XEP-0363
I refer so many demo like monal app but any demo can't clear anything.
so
Please help me.
There are a few ways to send images, one way is to create an API, and create a function for uploading images. So when you want to send an image, you can first call your API function, which will upload the image and then return the URL of the image. You can then send the URL in the <message> stanza, possibly in your own custom tags.
For example,
<message to=""...>
<image>http://example.com/myimg.jpg</image>
</message>
Of course it will then be up to the client to download the image.
Another way to do it is to convert the image to a base64 string, and send the base64 string in the message stanza. However I actually do not recommend doing so, as the base64 string can be extremely large, and sending large packets through xmpp isn't a good idea. Particularly if you are in a group chat with a lot of users, in which case it will have to send the large packet to many users, wasting up valuable bandwidth, as well as server space for any offline-stored messages.
You could of course use XEP-0363 as mentioned, but you just need to make sure your XMPP server supports it.

How to get a file from rails-api which using carrierwave?

I have a rails-api project, which provide the api to access my data.
I use carrierwave to store my file, my model called User and file attribute called image.
So, the image attribute contained the file_name, url and some other info.
In order to translate the file through the api, I added the gem carrierwave-base64.
I understand the Upload process. The client app encode the file to base64 code, then sent to backend by a json message. For example:
{user: {email: "test#email.com", image: "data:image/jpg;base64,#{base64_image}"}
So when the backend receive the json request, the carrierwave will parse the base64 code to a file and store it to local or S3
What I do not understand, is the Download process:
When I request the user info, what I assume is that the image file would be transfered as a base64 code in a json message, and then the client app will encode the base64 code to a file(image), and then display.
But actually, what I can provide for the json data, is the file url, not the base64 code.
The reason I want to get the file(image) from the api-server is because I don't want to the client app directly access s3 by url. So every time when the client app want to get a file, it will request the api-server, and api-server will get the file and transfer to the client.
Does anyone can explain how to do the download?
Or if I was thought in a wrong strategy, that I need another api endpoint to response a file object, not just accompany with user model.
Cheers.
Restricting Access to Objects Stored on Amazon S3
https://github.com/thoughtbot/paperclip/wiki/Restricting-Access-to-Objects-Stored-on-Amazon-S3
you did a good thing with uploading ,But while downloading you need to send URL no base64 and its traditional
Also for securrity purpose you can put public read permission on s3 while uploading and use expiring_url(60, :thumb) for your clients
In this URL get expired in time that you have specified

Posting form-data and binary data through AWS API Gateway

I'm trying to POST "mutlipart\form-data" to my EC2 instance through AWS API Gateway, but I couldn't find a way to this. There is a way to post data using "application/x-www-form-urlencoded" and Mapping Tamplate to convert it to JSON but still posting a binary data like an image file is missing I guess. Is there anything I'm missing ?
EDIT:
I have found another way:
I convert the image to base64 string then POST it as with content type "application/x-www-form-urlencoded". By this way I'm sending whole image as string. After I got the message I can convert it back to image in PHP. Only down side of this I could find is when I convert image to base64 its size gets a bit bigger. Other than that, I couldnt find any other downside. If there is could you please share with me ?
Api Gateway team here.
Binary data isn't supported at the moment, but it's on our backlog. Several customers have requested this.
Some customers have had success using the base64 util in the mapping templates which may get it working for you: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#util-template-reference
Other than that you'll have to wait for official support.
Edit
Binary support is finally here!!

Can I Tweet an image with just a URL?

I'm setting up the back end for an Android/iOS app that, among other things, allows users to share an image via Twitter. It's hosted on Heroku, which has no local image hosting, so the images are hosted elsewhere.
It looks like if you want to tweet an image you're supposed to POST to /statuses/update_with_media and send the image as multi-part data. But I don't have the images stored locally, so I would have to copy the image over to temp storage on Heroku, POST it to Twitter, and then delete it, which seems... inefficient.
Is there any way I can use Twitter's API to tweet an image and only supply the URL for the image?
It does not look like it's possible to send Twitter a link via their API, presumably because they would then have to download the image themselves. You could upload the image to a third party and link to that, but you have the same problem in that case.
You shouldn't need to copy the file over as such though, you could read the file into memory and serialize it to multi-part form data in order to send to Twitter.
Do you have any code to show?

How do I go about saving images sent across a JSON API in Rails?

Before I code this, I want to make sure that I go about it in the correct way. I have a mobile application that will send an image to the server through a JSON API, preferably as an attribute on the user (or whatever is being imaged).
My current idea is for the mobile application to send the image encoded in Base64, that way it can be included as text on the User resource API calls like so:
PUT "/users/1", {"image":"Base64EncodedImageString", "name":"Dan"}
But I've read that storing the image in Base64 will make the database too large too fast. So, my plan is to take that string, convert it to an image somehow (I'm sure it will have something to do with the Paperclip gem) and store it in the server's filesystem. The mobile app can then download those images directly through an image MIME type URL, which will be some URL tagged onto the user JSON:
{"name":"Dan", "image_url":"http://mysite.com/images/dan.png"}
Is this a sound idea?

Resources