I’m making an attempt to add a picture to a spring backend. It is presupposed to work when within the background, subsequently I can solely use the
My downside is that the backend is anticipating me to set a
Content material-Kind header. One essential half is to outline the
boundary and use it accordingly in my request physique, however how am I presupposed to set my
boundary on an Picture?
Most tutorials I’ve seen do that with the
session.uploadData perform, which is not out there once you wish to do the operation within the background. There I may merely append the
boundary to the information.
To summarise: How can I exploit the header discipline
boundary appropriately when importing pictures with
uploadTask(with request: URLRequest, fromFile fileURL: URL)?
I get this error from spring:
org.springframework.internet.multipart.MultipartException: Present request isn't a multipart request
let boundary = UUID().uuidString // A background add job should specify a file var imageURLRequest = URLRequest(url: uploadURL) imageURLRequest.httpMethod = "Put up" imageURLRequest.setValue("multipart/form-data; boundary=(boundary)", forHTTPHeaderField: "Content material-Kind") let imageTask = URLBackgroundSession.shared.uploadTask(with: imageURLRequest, fromFile: URL(fileURLWithPath: imagePath)) imageTask.resume()