-
Notifications
You must be signed in to change notification settings - Fork 2
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
Create /media
endpoint
#410
Conversation
multipartBodyBuilder.addFormDataPart(k, v) | ||
} | ||
val file = | ||
WpRequestExecutor::class.java.classLoader?.getResource(mediaUploadRequest.filePath())?.file?.let { |
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 not sure if this is the correct way to get the file in Android. I think it's correct, but we might need to pass a function in the initializer so it can be configured.
I am leaving it as is for now and we can address it if we find that it's not working when we integrate it to WordPress-Android.
96be16e
to
593db7e
Compare
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 works for me over in #412.
The code looks fine, the Android stuff included. That might be worth adding to the example app to be sure, but that could be a subsequent PR.
I took the liberty of pushing a commit to put Swift stubs in place to unblock CI.
* Create `/media` endpoint * Manually implement create media response type and endpoint * Restore test server from Kotlin * impl From<MediaCreateParams> for HashMap<String, String> * Implement MediaUploadRequestExecutionError * Removed addressed TODO from Kotlin WpRequestExecutor * Add file_path to MediaFileNotFound error * Patch up failing Swift stuff --------- Co-authored-by: Jeremy Massel <[email protected]>
Implements create
/media
endpoint. Due to its custom nature, it does NOT follow the established patterns, but instead requires some new patterns:MediaUploadRequest
that's similar toWpNetworkRequest
, but it includes information such asfile_path
&file_content_type
.MediaUploadRequestExecutionError
which is similar toRequestExecutionError
but it has an extra variantMediaFileNotFound
. We can add more error types specific to media uploads here.RequestExecutor
to upload media that uses the newMediaUploadRequest
andMediaUploadRequestExecutionError
.MediaUploadRequest
usesmultipart/form-data
content type header value and adds the parameters as form values. The header value is included in itsheader_map
and the key value pairs forMediaCreateParams
can be accessed from itsmedia_params()
function.I am a little concerned about the
clone
s inWpNetworkRequest
&MediaUploadRequest
and not entirely sure about the correct way to do this. From pure Rust perspective, this is definitely wrong. However, these types have to be cloned for FFI - or shared as a pointer. So, maybe we need to separate how Rust uses it and how it's exposed through FFI. I don't want to hold up this PR for this, so I opened a separate issue for it: #416