php - API-centric web application file upload -


i creating api-centric web application using php. have read lot of articles on api-centric arhitecture , design, have problem related file uploads.

suppose have image , want upload api server. how should upload image , how receive link image?

here how want create now:

  1. select image using <input type="file"> on client www.domain.com
  2. upload www.domain.com using post multipart/form-data
  3. send image put/post api call api.domain.com
  4. api.domain.com save image server static.domain.com , store image's id in database
  5. then, when need image, can use api call api.domain.com , receive image's url (something static.domain.com/image.jpg)

aditional questions:

  • is approach right 1 or doing wrong?
  • will need aditional server store uploaded files if application small, or can store files right on api server?
  • if store images on same server api server, won't strange if image urls api.domain.com/image.jpg?

p.s: can skip lot of api-related things need idea on how deal file uploads.

you haven't said kind of api going implementing here, assume restful api.

  • is approach right 1 or doing wrong?

no, wouldn't you're doing wrong. send file using post.

  • will need aditional server store uploaded files if application small, or can store files right on api server?

yes, allow store on same server, don't see why not. doubt use lot of storage, if application small.

  • if store images on same server api server, won't strange if image urls api.domain.com/image.jpg?

the api.domain.com/image.jpg technically url connect api , get/post data. not mean file going url. api return like:

{    type: "img",     id: "1",     url: "example.com/uploads/image.jpg" } 

i hope this helps, little!


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -