Skip to content
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

Missing method to create attachments for a Project Status Updates #157

Open
takraj opened this issue Oct 21, 2022 · 0 comments
Open

Missing method to create attachments for a Project Status Updates #157

takraj opened this issue Oct 21, 2022 · 0 comments

Comments

@takraj
Copy link

takraj commented Oct 21, 2022

Hi,

I'm using version 1.0.0 of this library from Maven Central: https://mvnrepository.com/artifact/com.asana/asana/1.0.0
This is the latest version by the time of creating this ticket.

I have encountered an issue of not being able to attach files to Project Statuses via the client API. There is simply no such method to call.

The documentation of this part also seems to be a bit ahead of time, because it presents the following Java example which uses a method that is not (yet?) available in the client:
https://developers.asana.com/docs/upload-an-attachment

Attachment result = client.attachments.createAttachmentForObject(file, parent, url, name)
    .data("field", "value")
    .data("field", "value")
    .option("pretty", true)
    .execute();

Instead, what the client currently offers is only usable for attaching files to tasks:

public ItemRequest<Attachment> createOnTask(String task, InputStream fileContent, String fileName, String fileType) {

I was able to work it around with the following class:

public class ExtendedAttachments extends Attachments {

        public ExtendedAttachments(Client client) {
            super(client);
        }

        public ItemRequest<Attachment> createOnProjectStatus(String projectStatus, InputStream fileContent,
                String fileName, String fileType) {
            return new ItemRequest<>(this, Attachment.class, "/attachments", "POST").data(
                    new MultipartContent()
                            .setMediaType(
                                    new HttpMediaType(ContentType.MULTIPART_FORM_DATA.getMimeType()).setParameter(
                                            "boundary",
                                            UUID.randomUUID().toString()))
                            .addPart(new Part()
                                    .setContent(new InputStreamContent(fileType, fileContent))
                                    .setHeaders(new HttpHeaders().set(
                                            CONTENT_DISPOSITION,
                                            format("form-data; name=\"file\"; filename=\"%s\"", fileName)
                                    )))
                            .addPart(new Part()
                                    .setContent(new ByteArrayContent(null, projectStatus.getBytes()))
                                    .setHeaders(new HttpHeaders().set(
                                            CONTENT_DISPOSITION,
                                            "form-data; name=\"parent\""
                                    )))
            );
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant