I want to use imgur's API to upload images however I don't want to use my server too much in the act because I'd like to keep bandwidth to a minimum.
The API accepts images in a base64 encoded string or binary.
Also if there's a way to encode images into base64 or binary in javascript that would be really useful to know too
JavaScript security restrictions prevent you from reading a local file and doing anything with it. That will be the reason that you cannot encode a file in Base64 and send it directly to that API.
Does Imgur have an API which accepts a direct file upload?
Related
I have a picture. For whatever reason, I need that picture to be sent to an environment that can only receive text and not images. Images and other files must be sent through their filter and I want to get around this. I calculated that there would be 480,000 independent hex values being manipulated but this is really the only option I have. Also, is it possible to compress and uncompress it for less pixels being sent? I will need to send the picture from a PHP web server [lets say, mysite.com/image.php] and receive it in Lua, and my only connection to the server is over a web request. No ftp, no even loading image files. Just setting 480,000 variables to the different id's
Oh, one more thing: it needs to not crash my server when I run it. ;)
Convert your image to base64 (Eg: Can pass to the variable).
Eg: I converted PNG image
Base 64 image will look like this.
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAYAAADEUlfTAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAE9JREFUeNpiYMADGLEJKssrCACp+Uw4JPYD8QdGHBIP7j58EMgCFDAAcvqBOBGI64FYAMpmYIFqAilYD6Udgbo+IBvXAMT/gXg9sjUAAQYAG6IS47QjgzEAAAAASUVORK5CYII="
You can use it in image source to display.
Hope this helps!
I'm trying to pass an image from Android application to php server.
I searched about that, I have two ways:
Sending by Multipart
Encode to Base64
I'm using Volley, I know about both but I don't know which is better for implementation.
Can you tell me which is standard and better?
Do not go with the base64 string since it may give you crash if it exceeds the limit. Better option to use the Multipart, it is reliable and safe.
I need to send images from server side to client side.
If I just echo the image data, it's not safe. In the client side, I need to process and use the images (I will use these images with web unity) but I don't want the original images to be exposed.
Any help is appreciated.
Will SSL do what you need?
If you need more (to prevent snooping), check out the http://php.net/manual/en/book.mcrypt.php library: you'll need to find a corresponding decryption function in Unity. Encypt the raw image data (e.g. jpeg or png) and send over the wire; decrypt in Unity and rebuild the image.
I have an image on a web page constructed like so:
<img src="data:image/png;base64;...." />
The contents of the image come from the user pasting into the browser. My question is how do I then upload the image to the webserver (PHP if that matters).
1) Take the src attribute with javascript (or the data submitted by user)
2) Submit it to the server 'as is' or cut and submit everything after base64; (AJAX or POST, method GET is probably not very suitable here for large images)
3) Decode base64 on server side (everything after base64; if not cutted), save the result as binary - it is an image.
That's it.
ps: just a reminder - by careful with possible code injection. Check the submitted data or somebody will upload encoded php script. Disable php engine in the folder with uploads and verify that the final result is an actual image (with the help of GD library, for example). Even if the script can not run on your server it could be used for malicious requests to other servers with php scripts.
Just post the base 64 encoded text to your server.
You could save it as...
file_put_contents($image, base64_decode($str));
I would like to use Flash to send a ByteArray (of a PNG image) to a php file, in a facebook application. Is there a way to do this by sending the ByteArray as just one POST variable instead of as the entirety of the POST data?
There was a nearly identical question here: How can I send a ByteArray (from Flash) and some form data to php? but the problem is different; instead of smuggling other variables in other parts of the request, the image itself has to be sent as just a variable because Facebook commandeers the post data and puts in its own junk.
Is this at all possible? If not, can I send the image in some form other than a byteArray?
I think the easiest way is base64 encoding the image before sending it. Then it's just a string and it's safe to pass it as a regular POST variable.
On the php side, you just have to base64_decode this string and then you have your image data ready to save it to file or whatever you need (you could also feed it to GD or other such library if you need to manipulate it first).
Another option, at least in theory is using multipart/data, just like you'd use in an html form to send a file, but if I recall correctly, the player does not allow to send files using this method (until version 9.0.124 or something like that, this was possible).
So, base64 is easy and simple and it only adds some overhead; 1/3 of the file payload in terms of size and some processing time as weel, but in most cases this isn't a big deal.