-
Notifications
You must be signed in to change notification settings - Fork 3
Generalize the file uploading implementation #977
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
Conversation
| throw RequestExecutionException.MediaFileNotFound(filePath = fileInfo.filePath) | ||
| } | ||
| val mimeType = fileInfo.mimeType ?: "application/octet-stream" | ||
| val requestBody = getRequestBody(file, mimeType, uploadListener) |
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.
@oguzkocer I'm not sure if the progress reporting is still working as expected. The previous implementation only supported uploading one file, but the new implementation supports uploading many files. I'm not sure if the uploadListener still works.
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.
This should be OK for this PR because /media only supports uploading a single file.
I am working on adding support for multiple files. However, since I also have a few other fixes/improvements in the Kotlin wrapper, so I want to split it into its own PR.
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 am working on adding support for multiple files.
Just to double check, by "support", do you mean support tracking the progress of uploading multiple files?
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.
Kind of, it's tracking cumulative progress. #979.
| .map(|(i, file_path)| { | ||
| ( | ||
| // TODO: The backend is not ready yet. This name may need to be changed. | ||
| format!("attachment_{i}"), |
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.
@jkmassel FYI, I presumed the attachment parameter is named "attachment_x" (and the app can control how many attachments are allowed). Still, we can always change this implementation after you have implemented the server side.
oguzkocer
left a comment
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.
Looks good ![]()
| throw RequestExecutionException.MediaFileNotFound(filePath = fileInfo.filePath) | ||
| } | ||
| val mimeType = fileInfo.mimeType ?: "application/octet-stream" | ||
| val requestBody = getRequestBody(file, mimeType, uploadListener) |
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.
This should be OK for this PR because /media only supports uploading a single file.
I am working on adding support for multiple files. However, since I also have a few other fixes/improvements in the Kotlin wrapper, so I want to split it into its own PR.
At the moment, the file upload API is hand-written and hard-coded for the
wp/v2/mediaendpoint. This PR implements a general solution for sending multipart/form-data POST requests.The existing core media upload endpoint has been migrated to the new approach. To summarize, this is how to implement an endpoint that accepts file uploading via multipart/form-data requests: