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:
- select image using
<input type="file">
on clientwww.domain.com
- upload
www.domain.com
usingpost
multipart/form-data
- send image put/post api call
api.domain.com
api.domain.com
save image serverstatic.domain.com
, store image's id in database- then, when need image, can use api call
api.domain.com
, receive image's url (somethingstatic.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
Post a Comment