How to upload project documents (zip files) via the HTTP API?

I guess that file documents need to be uploaded via "POST /api/http/uploads" with "storagePrefix: file". I managed to upload the file, get some kind of an id (like this 1NU9ho2sXaxE) and then use it as "blobId" with "POST /api/http/projects/{project}/documents" endpoint, but still getting the error: "File blob with the provided ID does not exist". What is the proper way to get a "blobId"?

1 comment
Comment actions Permalink

I haven't tried these steps for documents but they worked for me for creating issue's attachments (using "attachment" instead of "file" as "storagePrefix").

I think you need to do two different things. For uploading the file:

1. Call to post /api/http/uploads with storagePrefix=file to get a URL for the next step. You will receive something like  "/uploads/1234567890abcdef"

2. Upload the actual file calling `PUT/ uploads/1234567890abcdef/myfilename.pdf' passing the required parameters (PUT to {URL_RETURNED}/{YOUR_FILE_NAME} ). For example with cURL:

curl --location --request PUT 'https://example.jetbrains.space/uploads/1234567890abcdef/myfilename.pdf' \
--header 'Authorization: Bearer XXXXXXXXX' \
--header 'Content-Type: application/pdf' \
--data-binary '@myfilename.pdf'

After uploading the file probably you would be able to call "POST /api/http/projects/{project}/documents" endpoint with the "blobid" you already have.

0

Please sign in to leave a comment.