-
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
base: trunk
Are you sure you want to change the base?
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.
.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.
At the moment, the file upload API is hand-written and hard-coded for the
wp/v2/media
endpoint. 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: