-
Notifications
You must be signed in to change notification settings - Fork 31
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
All file object attributes being sent along with actual xhr #12
Comments
Yea the metadata for the file I think can be very useful and I think should stay as part of the file object. I think others will need that metadata, so they can quickly interpret mime type or image size so that can validate quickly as it goes through the Backbone Model class. If you want just the blob sent, I guess that's just up to hacking it up in the model to get that to work. Yea the flattening is required in order to go through the FormData API of the browsers which allows things like FileUploads whereas a normal Post doesn't allow Multipart since its just sending string data. This way the server reads it as multipart so it can stream the data through. There is an idea i have about actually converting the Blob Object into a normal JS object then appending it into the JSON object as string then you can use a traditional Post. Not sure if it's a good idea, but I'll experiment with that. That way you don't have to worry about "unflattening" attributes as they get pushed through. |
Sounds like a cool idea. The issue with flattening is that different web frameworks tend towards different defaults for how things should be flattened, rails uses Anyway, just food for thought. |
Actually I think i take it back since doing it all in a JSON post it won't "stream" but try to push the string all at once. So no POST JSON, we need to use the FormData API. |
Ah, didn't think of that. |
Hey, I've done a pretty minimal setup, with a single file attached to a model instance. It seems like there's a little bit of overhead going on in the upload xhr. Due to the flattening of attributes, I seem to end up with something like this being sent to the rails server.
The
#<ActionDispatch::Http>
stuff is just rails interpreting the raw bytes as a file (the bit that I want):The other attributes I'm just throwing away. I'll have a dig in and see if I can patch it up for my use case to not send file attributes, but was wondering if you want those attributes being sent or if it's just a side effect of accounting for nested objects in other attributes of the backbone model.
Cheers for a lovely plugin btw, perfect for my current use case.
The text was updated successfully, but these errors were encountered: