Important Update: Some Community URL Redirects are Under Maintenance. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Package Upload via REST API - File was an incorrect format for a package file

DMC_DM
Contributor III

Hi A-Team,

 

I want to upload a package from file system over REST API into Archer.

 

Now Archer gives me the following back:

 

Links : {}
RequestedObject :
IsSuccessful : False
ValidationMessages : {@{Reason=Validation; Severity=3; MessageKey=ValidationMessageTemplates:InvalidPackageFormat; Description=Unable to open package.; Location=-1;
ErroredValue=; Validator=ArcherTech.Kernel.Utility.BrokerHelper, ArcherTech.Kernel, Version=6.8.300.1028, Culture=neutral, PublicKeyToken=null;
XmlData=; ResourcedMessage=File was an incorrect format for a package file.}}‍‍‍‍‍‍

 

The headers are set, boundary and content-type, file is in boundary in body ...

 

Additional Information / Questions:

  • I tried to encode the file as UTF-8, ASCII and as Base64 String
  • Header with Authorization and ContentType = multipart/form-data with boundary
  • Body contains
    • Boundary
    • Content-Disposition: form-data; name="PackageBytes"; filename="Package_Test2.zip"
    • Content-Type: application/zip
    • Base64 String
    • Boundary
    • LF (empty Line)

 

Base64 String can be decoded (https://base64.guru/converter/decode/file ) and downloaded as ZIP file.

 

 

Anyone who can help? I tried already a lot of different ways - and now it's 01:29 in the night

 

Thank you!

Best regards,

Daniel

1 ACCEPTED SOLUTION

Accepted Solutions

DMC_DM
Contributor III

I'm sorry for the late answer, but here the important part of the PS script:

 

[System.Text.Encoding]::GetEncoding('ISO-8859-1').GetString($fileBytesIo);

 

Encoding is the key to success!

 

Full upload PS script:

 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} ;

###########################################################################################################################################
# Set the Instance information.
###########################################################################################################################################
$base_url = "https://localhost/RSAarcher"
$instance_name = "demo"
$user_domain = ""
$username = "myuser"
$password = "Password"
$FilePath = 'C:\folder\package.zip'



###########################################################################################################################################
# user authentication
###########################################################################################################################################
try {
$login_url = $base_url + "/platformapi/core/security/login"
$body = '{"InstanceName":"' + $instance_name + '","Username":"' + $username + '","UserDomain":"' + $user_domain + '","Password":"' + $password + '"}'
$response_login = Invoke-RestMethod -Method Post -Uri $login_url -Body $body -ContentType "application/json"
if(-Not ($response_login.IsSuccessful)){
Write-Error -Message "User Authentication error." -ErrorAction Stop
}
$session_token = $response_login.RequestedObject.SessionToken

} catch {
$_.Exception
return
}

$Headers = @{'Authorization' = 'Archer session-id="' + $session_token + '"'};

###########################################################################################################################################
# upload package
###########################################################################################################################################

$package_upload_url = $base_url + "/platformapi/core/package/upload"
$boundary = [System.Guid]::NewGuid().ToString()
$content_type = "multipart/form-data; boundary=" + $boundary
$LF = "`r`n";
$formFilename = "unknown"
$formName = "unknown"

try {
$fileBytesIo = [System.IO.File]::ReadAllBytes($FilePath)
$fileEncIso = [System.Text.Encoding]::GetEncoding('ISO-8859-1').GetString($fileBytesIo);
$formFilename = [System.IO.Path]::GetFileName($FilePath)
$formName = [System.IO.Path]::GetFileNameWithoutExtension($FilePath)
} catch {
Write-Error "System IO File Exception Message:" $_.Exception.Message
return
}


$bodyContentDisposition = "Content-Disposition: form-data; name=`"" + $formName + "`"; filename=`"" + $formFilename + "`""
$bodyLines = (
"--$boundary",
$bodyContentDisposition,
"Content-Type: application/zip$LF",
$fileEncIso,
"--$boundary--$LF"
) -join $LF


try {
$response_upload = Invoke-RestMethod -Uri $package_upload_url -ContentType $content_type -Method Post -Headers $Headers -Body $bodyLines
if(-Not ($response_upload.IsSuccessful)){
Write-Error -Message "Package upload error." -ErrorAction Stop
}
$response_upload.IsSuccessful
} catch {
$_.Exception
return
}

 

Would be cool if RSA will update the manual / help

 

Hope that help you guys!

Daniel

View solution in original post

6 REPLIES 6

BodieMinster
Archer Employee
Archer Employee

Have you attempted to upload the package through the UI? This would rule out your integration code as a possible source of error.

Hi Bodie,

 

I created the package in the instance and tried also to upload it through UI. I also tried the ArcherToolBox Package as file, but the error is still the same. 

 

Body looks like:

 

---------------------------acebdf13572468
Content-Disposition: form-data; name="Archer_Toolbox"; filename="Archer_Toolbox.zip"
Content-Type: application/zip
UEsDBBQAAAAIALp6vFDuqWTEoAMAAJEJAAAcAAAAZW4tVVMvYXJjaGVycGFja2FnZS5tYW5pZmVzdJVW247bNhD9FUIPeSp1s2zJXq8D106CLTbJZuOkQN8oaWSzpkiBpHz5m/5HHwrkh/ILpWTJl3ZjOTBkyOSZy5mZM/D3v/8Zv97l
oWAJyKlfHlvlTrDkfV6Mn5POM1AafT1DFl9LGTsubq3VloXI8fZbrc2kckKpM1BO77ruU5BkjVZGodO3rixJuOn+

[.....]
G9yeUZpbGVzLnhtbFBLAQItABQAAAAIALp6vFAdcH8gCwEAALIBAAAVAAAAAAAAAAAAgAAAAOW8AABlbi1VUy9Vc2Vyc0dyb3Vwcy54bWxQSwECLQAUAAAACAC6erxQcSAyyNIKAABvkgAAFQAAAAAAAAAAAIAAAAAjvgAAZW4tVVMvV
4ueG1sUEsBAi0AFAAAAAgAunq8UOy3jFUuAAAALAAAAAcAAAAAAAAAAACAAAAAKMkAAC9oaWRkZW5QSwUGAAAAAB
---------------------------acebdf13572468--

 

Have you ever used the REST API to upload a package?

 

Thank you Bodie!

Are you creating the package in the same instance where you are trying to ingest it? If not, are the two instances the same version of Archer? 

 

If you can't ingest the package through the UI, then the problem is not the API call, but the package itself.

Yes, I missed to answer your question - sorry!

 

So I can upload both packages via UI. The one I created in that instance and the ArcherToolBox as well...

DMC_DM
Contributor III

Short Update: I know how to upload the attachment now. I'll update this thread later that week and add all necessary details!

DMC_DM
Contributor III

I'm sorry for the late answer, but here the important part of the PS script:

 

[System.Text.Encoding]::GetEncoding('ISO-8859-1').GetString($fileBytesIo);

 

Encoding is the key to success!

 

Full upload PS script:

 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} ;

###########################################################################################################################################
# Set the Instance information.
###########################################################################################################################################
$base_url = "https://localhost/RSAarcher"
$instance_name = "demo"
$user_domain = ""
$username = "myuser"
$password = "Password"
$FilePath = 'C:\folder\package.zip'



###########################################################################################################################################
# user authentication
###########################################################################################################################################
try {
$login_url = $base_url + "/platformapi/core/security/login"
$body = '{"InstanceName":"' + $instance_name + '","Username":"' + $username + '","UserDomain":"' + $user_domain + '","Password":"' + $password + '"}'
$response_login = Invoke-RestMethod -Method Post -Uri $login_url -Body $body -ContentType "application/json"
if(-Not ($response_login.IsSuccessful)){
Write-Error -Message "User Authentication error." -ErrorAction Stop
}
$session_token = $response_login.RequestedObject.SessionToken

} catch {
$_.Exception
return
}

$Headers = @{'Authorization' = 'Archer session-id="' + $session_token + '"'};

###########################################################################################################################################
# upload package
###########################################################################################################################################

$package_upload_url = $base_url + "/platformapi/core/package/upload"
$boundary = [System.Guid]::NewGuid().ToString()
$content_type = "multipart/form-data; boundary=" + $boundary
$LF = "`r`n";
$formFilename = "unknown"
$formName = "unknown"

try {
$fileBytesIo = [System.IO.File]::ReadAllBytes($FilePath)
$fileEncIso = [System.Text.Encoding]::GetEncoding('ISO-8859-1').GetString($fileBytesIo);
$formFilename = [System.IO.Path]::GetFileName($FilePath)
$formName = [System.IO.Path]::GetFileNameWithoutExtension($FilePath)
} catch {
Write-Error "System IO File Exception Message:" $_.Exception.Message
return
}


$bodyContentDisposition = "Content-Disposition: form-data; name=`"" + $formName + "`"; filename=`"" + $formFilename + "`""
$bodyLines = (
"--$boundary",
$bodyContentDisposition,
"Content-Type: application/zip$LF",
$fileEncIso,
"--$boundary--$LF"
) -join $LF


try {
$response_upload = Invoke-RestMethod -Uri $package_upload_url -ContentType $content_type -Method Post -Headers $Headers -Body $bodyLines
if(-Not ($response_upload.IsSuccessful)){
Write-Error -Message "Package upload error." -ErrorAction Stop
}
$response_upload.IsSuccessful
} catch {
$_.Exception
return
}

 

Would be cool if RSA will update the manual / help

 

Hope that help you guys!

Daniel