best approach to design a rest web service with binary data to be consumed from the browser

前端 未结 3 1546
礼貌的吻别
礼貌的吻别 2020-12-12 18:25

I\'m developing a json rest web service that will be consumed from a single web page app built with backbone.js

This API will let the consumer upload files related t

3条回答
  •  孤街浪徒
    2020-12-12 19:02

    I can't think of any other approaches off the top of my head.

    Of your 3 approaches, I've worked with method 3 the most. The biggest difference I see is between the first method and the other 2: Separating metadata and content into 2 resources

    • Pro: Scalability
      • while your solution involves posting to the same server, this can easily be changed to point the content upload to a separate server (i.e. Amazon S3)
      • In the first method, the same server that serves metadata to users will have a process blocked by a large upload.
    • Con: Orphaned Data/Added complexity
      • failed uploads (either metadata or content) will leave orphaned data in the server DB
      • Orphaned data can be cleaned up with a scheduled job, but this adds code complexity
      • Method II reduces the orphan possibilities, at the cost of longer client wait time as you're blocking on the response of the first POST

    The first method seems the most straightforward to code. However, I'd only go with the first method if anticipate this service being used infrequently and you can set a reasonable limit on the user file uploads.

提交回复
热议问题