Hello,
I'm using a legacy cloud script where I access a file stored in the title player player account by making a GET request to the DownloadUrl provided in the meta data retrieved by GetFiles(). The file contains binary data that was uploaded by the client using the File / Data REST API and libcurl to put the contents. This file should be uploaded to another server to be attached to an open issue.
I verified that the uploaded file contents are valid by manually downloading the file from the players file section.
Here is a part of the script up to the GET request.
// ...
var entityProfile = context.currentEntity;
var getFileRequest = {
Entity : entityProfile.Entity
};
var file_url;
var result = entity.GetFiles( getFileRequest );
if ( result && result.Metadata )
{
var file_meta = result.Metadata["bug.t7s"];
if ( file_meta )
{
file_url = file_meta.DownloadUrl;
}
if ( file_url )
{
var headers = {
"Accept": "application/octet-stream"
};
var get_response = http.request( file_url, "get", "", "", headers, true );
// ...
After executing the this GET request, get_response.length contains the correct number of characters (== file size), but debug printing the individual characters of the string get_response showed that several characters of the original byte-sequence where replaced by the unicode replacement character (0xFFFD), which renders the received file contents invalid for further processing.
The final step would be a REST call to an external service, using get_response as content of a multipart/form-data post request
// Create the attachment.
var auth = "omitted auth string";
var headers = {
"Authorization": auth,
"X-Atlassian-Token": "no-check"
};
content =
"--partboundary" +
"\r\nContent-Disposition: form-data; name=\"file\"; filename=\"bug.t7s\"" +
"\r\nContent-Type: application/octet-stream" +
"\r\n" +
"\r\n" + get_response +
"\r\n--partboundary--"
var url = "omitted target url";
var httpMethod = "post";
var contentType = "multipart/form-data; boundary=partboundary";
var response = http.request(url, httpMethod, content, contentType, headers, true);
This calls succeeds but posts invalid / broken data to the target site.
Have you any advice how I can solve this problem?