-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide example for uploading to an ActiveModelAdapter-API #42
Comments
I did the following: const picture = this.store.createRecord('picture', {
file: file
});
file.read().then(function (dataUrl) {
if (get(picture, 'url') == null) {
set(picture, 'url', url);
}
});
return file.upload('/picture/upload').then(function (response) {
picture.set('url', response.headers.Location);
picture.set('file', null);
return picture.save();
}); Setting the file object on the picture allows for progress to be shown while the file is still being uploaded. Once the file is uploaded, the url can be set to the one provided by the server and it the file can be removed as a temporary variable. |
Yeah, I guess there is not really an easy way to integrate this fully with Ember Data. If one wanted to achieve this, uploadPicture(file) {
file.upload({
url: /* your url*/,
headers: {
// authorize against backend here
}
}).then(
(success) => {
const picture = this.get('mainStore').findRecord(
'picture',
success.body.picture.id
); //optional
},
(failure) => {
file.destroy();
//...
}
);
}, This works fine, because everything is handled at the Rails API. If you upload to |
Hmm. This seems like it may be nice to bake this into the addon in some way? I feel that I don't have a clear idea of what common patterns could be extracted out at the moment. |
Ember is often used on top of a data API (e.g. a Rails server). If you want to save data to the API, you update your model on the client side and
save()
it. A post request is then send to the API connected via e.g. ActiveModelAdapter. I am not sure how to approach this with the plupload workflow of file-read/upload -> model.save.I can do this to save an image to my API:
So the uploading part is happening after
save
and the upload url is provided by the application adapter. Thus, I can't use upload progress etc. Do you have any preferred appoach to this?The text was updated successfully, but these errors were encountered: