We are using Forge's Design Automation API and we want to send a .zip
in the WorkItem to the AppBundle.
So our Activity parameter looks like this:
"inputZip": {
"verb": "get",
"description": "input file",
"localName": "test.zip",
"ondemand": false,
"required": false,
"zip": true
},
The Websocket argument is:
"inputZip: { localName: \"test.zip\", url: \"" + url + "\"},
This part looks alright, at least we don't have any errors in this part, however, then comes the AppBundle
code:
string destinationPath = "none";
string extractPath = Path.GetFullPath(currentDir);
if (!extractPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
{
extractPath += Path.DirectorySeparatorChar;
}
using (ZipArchive zip = ZipFile.Open(@".\test.zip", ZipArchiveMode.Read))
{
foreach (ZipArchiveEntry entry in zip.Entries)
{
if (entry.FullName.EndsWith(".rfa", StringComparison.OrdinalIgnoreCase))
{
entry.ExtractToFile("testExtractedFile");
// Gets the full path to ensure that relative segments are removed.
destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName));
if (destinationPath.StartsWith(extractPath, StringComparison.Ordinal))
{
entry.ExtractToFile(destinationPath);
}
Console.WriteLine(" * - * File name = " + entry.FullName);
Console.WriteLine(" * - * File extracted from zip file succesfully! * - * ");
//entry.Open();
}
}
}
var familyFullPath = destinationPath;
The problem is that we are unable to open the zip file, we get the following error:
System.UnauthorizedAccessException: Access to the path 'T:\Aces\Jobs\...\test.zip' is denied.
The error happens at line using (ZipArchive zip = ZipFile.Open(@".\test.zip", ZipArchiveMode.Read))
. Any idea how to bypass this?
The idea is to extract 2 files which are located in this one particular zip file in the AppBundle, and then open one of them with document.LoadFamily(familyFullPath, out Family family)
(one of the files is a family file)
The zip is uncompressed to the folder specified in localname. Please refer to: https://aps.autodesk.com/en/docs/design-automation/v3/reference/http/workitems-POST/#body-structure -> arguments -> * -> XrefTreeArgument -> pathInZip