taskadapter / redmine-java-api

Redmine Java API
Apache License 2.0
270 stars 163 forks source link

Attachment upload is not working with extension restriction #337

Closed Zylfier closed 4 years ago

Zylfier commented 4 years ago

Hello,

I'm facing with a very strange issue. I want to upload attachment but the request fails every time with status code 422 (Unprocessable entity) and then I get "Attachment extension is not allowed" error message. I figured it out that this happen when Allowed extensions/Disallowed extensions features are in used on Redmine side.

I found a documentation defect which has been already fixed but it contains some very intresting comments https://redmine.org/issues/30428

It say that we should provide a filename parameter in the request otherwise it will always fails with a 422 (If the filename parameter is missing then Redmine generate a random string for filename without any extension)

I checked the uploadAttachment function in your codebase and I think that this function is not sending the filename :)

 public Attachment uploadAttachment(String fileName, String contentType, InputStream content, long contentLength) throws RedmineException, IOException {
    final InputStream wrapper = new MarkedInputStream(content,
            "uploadStream");
    final String token;
    try {
        token = transport.upload(wrapper, contentLength);
        return new Attachment(transport)
                .setToken(token)
                .setContentType(contentType)
                .setFileName(fileName);
    } catch (RedmineException e) {
        unwrapException(e, "uploadStream");
        throw e;
    }
}

I would like to ask for your help. Is this really a bug or I misunderstand something?

Thank you in advance.

PS:I am using com.taskadapter:redmine-java-api:4.0.0.preview.1