Search code examples
javauploadminio

Unable to upload file via uploadlink generated by minio


I have a backend that returns uploadlink via minio server, when an API call is made to an endpoint, /attachments in my case. This is the POST handler in backend.

@POST
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.TEXT_PLAIN})
public String migrateToMinio(Attachment attachment) throws Exception {
    Integer id = attachmentService.createNew(attachment);  
    String uploadLink = minioFileServer.getUploadLinkForFile("test", attachment.getUuid(), attachment.getName());        
    return uploadLink;
}

when I send a POST request to this API via Postman, I get an uploadlink as a response. enter image description here

But, when I use CURL to upload the file to that uploadlink, using this command

curl "http://127.0.0.1:9000/test/49fa2963-f44b-481d-a6c4-cdd2cd25e3bb/a.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=9LPWUPSK3DEO66JR04LD%2F20180921%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180921T152901Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=73dfe83f6b44a19d77ab08c9317b5bbda213e6ea9e50541f6b664d0e103909d0" -F "file=@/Users/Roshan/Desktop/a.txt"

It gives me an error saying the method is not allowed, like this: enter image description here

But, when I generate an uploadlink manually using minio client and CURL to that link with file location, it works just fine. I would really appreciate any help/suggestion with this.


Solution

  • Turns out I was doing it all wrong. When I sent a PUT request to the upload link generated by the minio server, the upload worked just fine, with an HTTP 200 OK! enter image description here

    I hope this helps someone, in case they are having the same problem.