简体   繁体   中英

How to save a java-generated base64 image to server?

I've been struggling with this for the last few hours and can't seem to figure it out at all. To start I'll lay out what I'm trying to do.

I want to make it so that when you generate a craft idea on this page

http://craftspo.com/craft-idea-generator/

it saves an image of the idea on my server (so that I could then allow the user to pin it on Pinterest, share it on FB, and so on).

So far, I've managed to get it so that when they click the button, it uses html2canvas to snag a snapshot of the table. The problem is that image ends up being in base64, so it's pretty much unusable.

From what I've read, you can really only decode (and then save) base64 images to a server using PHP. And of course PHP is only called whenever you load the page but I'd rather not make them reload the page every time they generate a new idea. So is there anything else I can do? Even if it means doing something completely different. At this point, I just wanna make it happen so I can feel like I conquered the problem!

if I recall correctly base64 or image has no different, just like the comment above you could use it like :

<img src="data:image;base64,etc"/>

if you don't want the user to reload, you could use ajax to replace the src using javascript/jquery, you could just replace it with base64 image instead link to image. if the image ain't that big, I myself would prefer to use base64, you could also save the base64 string into database, if it could hold the length :D

and use it later on

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM