1

I have an tag on my website that is generated from a canvas like from camanjs

Caman('#my-image', function () {
    this.brightness(10);
    this.contrast(30);
    this.sepia(60);
    this.saturation(-30);
    this.render();
  });

The canvas can be converted to a base64 like this:

var strDataURI = oCanvas.toDataURL();  
// returns "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACt..."

How can I send this image (2MB - 10MB) to my server?

I know I can use this:

$.ajax({
    type: 'POST', //or get
    url : 'urlToMyServer.php',
    data: { img : $('img').attr('src') }
});

Is this a good way for images <10MB?

Michael
  • 32,527
  • 49
  • 210
  • 370
  • http://learn.jquery.com/ajax – Jason P Sep 17 '13 at 21:00
  • you can send that using ajax to the server, then in the server save that data to a file. – ravenlp Sep 17 '13 at 21:02
  • Is this the correct way of doing that if I have <10MB files? – Michael Sep 17 '13 at 21:05
  • `POST` is fine. `GET` doesn't get you far as it's limited in size. BASE64 is bigger than other formats... maybe you want to zip it with a compression framework... – jsmorph Sep 17 '13 at 21:18
  • @jsmorph how would you do that with the zip? – Michael Sep 17 '13 at 21:58
  • 1
    @confile see http://stuk.github.io/jszip/ or google 'zip javascript' – jsmorph Sep 17 '13 at 22:03
  • @jsmorph do you think that zip a jpg will help? I think the compression factor will be very low. – Michael Sep 17 '13 at 22:10
  • @confile It always depends on: would you like to bother the client with higher transfers or with the client's processor usage (making sure nothing goes wrong there...). You have to make a decision here anyhow. Downloading a framework like jszip also stresses bandwidth... I'd stick with sending just the BASE64 data... It also depends on what you want to do and how often you'll send the data of an image. – jsmorph Sep 17 '13 at 22:15
  • @jsmorph I want to upload an image from the client to the browser. The image is processed in the browser and then sent as base64 to the server as fast as possible. Usually, the image which is uploaded to a browser is a jpg. So what do you recommend? Do you think zip is the best to get the image as fast as possible to the server? – Michael Sep 17 '13 at 22:31
  • @confile: You probably mean from the server to the client? What I mean is that, if you're realizing a image manipulation software and you want to save every step the client does on the server, you might to go for zip, otherwise, just go for the 'RAW'-data (BASE64). Read this for more info about data increase of BASE64: http://stackoverflow.com/questions/4715415/base64-what-is-the-worst-possible-increase-in-space-usage – jsmorph Sep 17 '13 at 22:46
  • @jsmorph What I mean: Do you think sending a base64 from the browser (generated by js) to the server should be as zip? – Michael Sep 17 '13 at 22:49

0 Answers0