While downloading the zip archive, the .zip extension is not present in the folder.
完了When trying to download a zip archive from a query parameter in url with box id, I receive the downloaded file successfully. However, it's missing the ".zip" extension in its name. For example, if the zip archive is named "downloadzip", the downloaded file should ideally be named "downloadzip.zip", but it isn't. Am I missing something? According to this article (https://developer.box.com/reference/post-zip-downloads/), it explicitly states that ".zip" is added from the Box API.
public async Task<MemoryStream> GetStreamForZip(string csvFileIds)
public async Task<MemoryStream> GetStreamForZip(string csvFileIds)
{
var fileIds = csvFileIds.Split(',');
var request = new BoxZipRequest
{
Name = "downloadzip",
Items = fileIds.Select(fileId => new BoxZipRequestItem
{
Id = fileId.Trim(),
Type = BoxZipItemType.file
}).ToList()
}; using (MemoryStream ms = new MemoryStream())
{
await BoxClient.FilesManager.DownloadZip(request, ms);
ms.Position = 0;
return ms;
}
}
var fileIds = csvFileIds.Split(',');
var request = new BoxZipRequest
{
Name = "downloadzip",
Items = fileIds.Select(fileId => new BoxZipRequestItem
{
Id = fileId.Trim(),
Type = BoxZipItemType.file
}).ToList()
}; using (MemoryStream ms = new MemoryStream())
{
await BoxClient.FilesManager.DownloadZip(request, ms);
ms.Position = 0;
return ms;
}
}
[FunctionName("downloadzip")]
public static async Task<IActionResult> DownloadZip([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
try
{
string id = req.Query["id"];
if (string.IsNullOrEmpty(id))
{
return new BadRequestObjectResult("Document id is not passed. Pass id as request param.");
} var stream = await _boxIntegrationService.GetStreamForZip(id); if (stream == null)
{
return new BadRequestObjectResult("The file is not found");
} var bytes = stream.ToArray();
return new FileContentResult(bytes, "application/octet-stream");
}
catch (Exception ex)
{
return new BadRequestObjectResult(ex.Message);
}
}
public static async Task<IActionResult> DownloadZip([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
try
{
string id = req.Query["id"];
if (string.IsNullOrEmpty(id))
{
return new BadRequestObjectResult("Document id is not passed. Pass id as request param.");
} var stream = await _boxIntegrationService.GetStreamForZip(id); if (stream == null)
{
return new BadRequestObjectResult("The file is not found");
} var bytes = stream.ToArray();
return new FileContentResult(bytes, "application/octet-stream");
}
catch (Exception ex)
{
return new BadRequestObjectResult(ex.Message);
}
}
サインインしてコメントを残してください。
コメント
2件のコメント