Solved

Image downloading intermittent issues

  • 24 November 2022
  • 2 replies
  • 85 views

Userlevel 2
Badge

Hello, I have a process that syncs stockitems from Acumatica for use on an external eCommerce web application. 

I download the images as part of the sync and store them in Azure storage. The web application loads the images from the storage accounts.

I am finding that when I download a batch of images...perhaps syncing 10 products in a batch, I will get the first 3 images and then the response stops sending any content. I get an HTTP 200, but I receive no bytes in my download.

If I slow down my process it seems to work better.

I have seen similar issues when calling the rest API. If I download 1 product at a time, if my sync process goes too fast, Acumatica sends empty results….no error or anything like that. I was able to work around that issue by downloading batches of stock items in groups of 500 and storing the raw JSON to the DB and then doing the ETL steps after. 

 

Is there some sort of limit in Acumatica or a better approach to fetching the images? I have my service account set to unlimited requests.

 

Here is my code snippet:

        public async Task<byte[]> DownloadImageAsync(string imageId, string fileName)
{
using (HttpClient client = new HttpClient())
{

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", $"{Helper.CurrentAuthToken.Replace("Bearer ", "")}");
string fullPath = $"{_restClient.BaseUrl}files/{imageId}";
Uri uri = new Uri(fullPath);

using (HttpResponseMessage response = await client.GetAsync(uri))
{
using (Stream streamToReadFrom = await response.Content.ReadAsStreamAsync())
{
if (streamToReadFrom != null)
{
var bytes = this.streamToByteArray(streamToReadFrom);

return bytes;
}
}
}

}

return null;

}

 

Thank you for your help!

icon

Best answer by Troy Vars 2 December 2022, 19:23

View original

2 replies

Userlevel 4
Badge +2

I had to add a delay when working with files esp. large file sizes. This probably has to do with the API processing throttles and limits imposed by Acumatica. 

Because these call are running Async they will send more concurrent requests than allowed for the license you will be throttled per this article

https://help-2022r2.acumatica.com/Help?ScreenId=ShowWiki&pageid=7a796856-3dec-4a4f-abf8-171324c9642b

Userlevel 2
Badge

Makes sense. I am going to make a dedicated sync just for images and I can throttle it. I guess I’ll remove the multi-threading too.

Thank you for your help!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved