2

So far we've been using Backbone in JavaScript along with a Java Servlet to sync data between our client and our server. We use Jackson to turn the JSON into a Java Object serverside.

Our model is a profile object that contains basic information about the user such as name, email, etc. and now we want to add a profile picture to that object.

We've experimented with FileReader--uploaded the image on the client and then converted it to Base64. This works well for uploading with JSON. But We have now learned that FileReader is not fully supported (specifically on older versions of IE and Safari, as well as some mobile browsers).

We have thought about doing a form multi-part upload, but then we would have to break backbone since we would no longer be sending json during a save. It's also not clear if we could automatically parse our data into into a JavaObject using Jackson, or if we would have to do it ourselves. File upload seems fairly straight-forward, but automatic marshaling does not.

Surely someone has run into this problem before?

Community
  • 1
  • 1
Jason
  • 13,563
  • 15
  • 74
  • 125

1 Answers1

2

My thought on image upload: for the browsers that support it, continue doing Base64. That way you use Base64 and JSON like intended. It looks like all versions of Chrome, Firefox, and the newest versions of Safari and Internet explorer support it.

Then, for those who don't support it, do two api calls: one to upload the image (that returns a url), and one to upload the merchant data (with the url). That way we can still use backbone/json/jackson for the merchant data, while maintain backwards compatability

Jason
  • 13,563
  • 15
  • 74
  • 125
Cristiano
  • 2,839
  • 8
  • 25
  • 35