-
Notifications
You must be signed in to change notification settings - Fork 2k
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
companion: set upload filename from metadata during uploads #1587
Conversation
@@ -329,10 +331,7 @@ class Uploader { | |||
* start the tus upload | |||
*/ | |||
uploadTus () { | |||
const fname = path.basename(this.options.path) | |||
const ftype = this.options.metadata.type | |||
const metadata = Object.assign({ filename: fname, filetype: ftype }, this.options.metadata || {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hah ok, so we did already do it here!
this.path = `${this.options.pathPrefix}/${Uploader.FILE_NAME_PREFIX}-${this.token}` | ||
this.metadata = Object.assign({}, this.options.metadata || {}) | ||
this.metadata.filename = this.metadata.name || path.basename(this.path) | ||
this.metadata.filetype = this.metadata.type | ||
this.streamsEnded = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding this filename
and filetype
conversion to uploadRemote
on @uppy/tus
client instead? Then it’s consistent — tusd expects metadata this way, it doesn’t convert name
to filename
for you, and so will Companion. We have that conversion for direct uploads, and we’ll do the same in the same place for remote uploads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we have to keep it in companion until 2.0 :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s right, forgot about that, good catch! But what about adding it on the client anyway, then we can add a 2.0 todo to remove on Companion and forget about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding this filename and filetype conversion to uploadRemote on @uppy/tus client instead? Then it’s consistent
@arturi but then we'd have to change it for XHR-Uploads too. And as you can see from the code, the way companion sets filetype
for multipart is quite different and prone to change depending on the request library used. So I don't think it matters if we change it from the client. So long as companion knows what to expect, it can change it accordingly
Do we want this too? We get the path when a folder with files is dropped in uppy. #1509 the property is |
We discussed in Slack that meta like |
@arturi I'll rather try to avoid this now, as I am not sure of the security implications |
Discussed with Ife. Because the |
contentType: this.options.metadata.type | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a comment/link here too, as to why filename
and contentType
? Stating that it’s conventional and linking to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Directives and https://github.com/request/request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be redundant because Content-Disposition
is pretty common and that's what the browser also uses, and the library used is request
so linking to request
is unnecessary because this exact example is in the readme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I’ll leave a link here then: https://github.com/request/request#multipartform-data-multipart-form-uploads
metadata, | ||
metadata: Object.assign( | ||
{ | ||
// file name and type as specified by tus protocol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking, but is it defined by the protocol, or just the tusd implementation? I didn’t find it in the protocol, so maybe linking here: https://github.com/tus/tusd/blob/5b376141903c1fd64480c06dde3dfe61d191e53d/unrouted_handler.go#L614-L646?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filename
is mentioned a few times in the protocol https://github.com/tus/tus-resumable-upload-protocol/blob/master/protocol.md#protocol-extensions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since filetype
is not documented, I have added a comment to the URL you shared
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested again locally with latest changes, works 👌
I think it’s good to go! Nice work! |
Changes look solid! In xhr-upload client uploads, we use the original file name and type instead of the metadata file name and type. So there will be a difference between client and remote uploads still with this PR. I think using metadata is probably better though. Maybe we can still do this and then change the name/type for xhr-upload client uploads in a minor release? It would be a breaking change but on an extreme technicality so it may be fine. The only problem is that changing the type may be harder for client uploads. You can create a new Blob but I don't know if that will affect memory usage/performance. |
To recap from the call: We'll merge this first, then change the xhr-upload client uploads to send metadata name and type instead, by putting |
companion: set upload filename from metadata during uploads
fixes #1409