The backend expects to receive a null value when using data part with multipart/form-data
sokarcreative opened this issue · comments
Question
Description
I've been used to Fuel for a long time and I'm probably asking here a stupid question but I'm not used to communicate with the backend with multipart/form-data.
I cannot send a "null" value as DataPart of UploadRequest.
UseCase - send to the backend a file datapart with a specific key with value set to null
// key is here: user[avatar]
private fun UploadRequest.addPhotoAction(key: String, photoAction: PhotoAction){
when(photoAction){
is PhotoAction.Defined.Set -> { // works fine
val file = File(UriCompose.getPathFromInputStreamUri(context = applicationContext, photoAction.uriString.toUri()))
if(file.exists()){
add(FileDataPart(file = file, name = key, contentType = ContentTypeMultiPartSupported.MultiPartFormData.contentType))
}
}
is PhotoAction.Delete -> { // !!! cannot set the file parameter to null !!!
// cannot set a file parameter value to null
add(FileDataPart(file = null, name = key, contentType = ContentTypeMultiPartSupported.MultiPartFormData.contentType))
// cannot either set a content parameter value to null
//add(InlineDataPart(content = null, name = key, contentType = ContentTypeMultiPartSupported.Text.contentType))
}
}
}
Expected behavior
The backend expects to receive a null value and I cannot set a null value to a content/file parameter of DataPart
Just wondering when we send null
, what exactly the backend would receive? It is a string "null" or something?
I had my answer 5 days ago and I forgot to close this issue (I was busy this week). It was an issue from the backend developer. There is no way in multipart to send a value to "null". Just ends up to communicate in another way. Sorry to disturb you. Great library by the way. I close the issue.