Service API Catalog Import

Vote:
 

Hi All,

I've been trying to use the new Service API to perform regular imports and updates to a catalog. But I'm really struggling to get the POST to /episerverapi/commerce/import/catalog to work. The exception stack trace is shown below.

2016-03-20 09:31:40,097 [116] ERROR EPiServer.ServiceApi.Extensions.HttpRequestMessageExtensions: File is not uploaded, please check permission on your app data folder in episerverframework.config file.
System.IO.IOException: Unexpected end of MIME multipart stream. MIME multipart message is not complete.
at System.Net.Http.Formatting.Parsers.MimeMultipartBodyPartParser.d__0.MoveNext()
at System.Net.Http.HttpContentMultipartExtensions.d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.HttpContentMultipartExtensions.d__0`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at EPiServer.ServiceApi.Extensions.HttpRequestMessageExtensions.d__0.MoveNext()
System.IO.IOException: Unexpected end of MIME multipart stream. MIME multipart message is not complete.
at System.Net.Http.Formatting.Parsers.MimeMultipartBodyPartParser.d__0.MoveNext()
at System.Net.Http.HttpContentMultipartExtensions.d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.HttpContentMultipartExtensions.d__0`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at EPiServer.ServiceApi.Extensions.HttpRequestMessageExtensions.d__0.MoveNext()

I know the error message says to check the permissions on the app_Data folder. But I've double and triple checked permissions even to the point of adding full writes on the folder to everyone. I'm kind of thinking this may not be a permissions issue because the service does get to the point of creating the "integration" folder under App_Data before the exception is thrown.

Just in case it was something to do with permissions I've also now changed computers to see if it was some sort of security restriction on my office computer. But that is not the case as I get the same issue at home.

Been looking into this for the last few days and can't think of anything else to try so any help is greatly appreciated. Please note I've tried the majority of the other operations and they all work fine. It is just the bulk catalog import/update that is causing me grief.

The versions I'm using are:

EPiServer CMS v9.7.2

EPiServer Commerce v9.10

EPiServer Service API v2.05

The code I'm using to make the request is identical to what is shown on http://world.episerver.com/documentation/Items/Episerver-Service-API/Using-bulk-import-and-export-methods/Using-the-catalog-service/

Thanks heaps,

Damo

#146630
Mar 19, 2016 23:58
Vote:
 

Hi,

How did you post the file? I suppose you have a page to select the file and then post it to ServiceAPI?

This should not be permission issue. It's only suggestion of the most common cause, but the true error was this:

Unexpected end of MIME multipart stream. MIME multipart message is not complete.

So I guess it's how you send the file to ServiceAPI. If you are using an input to select the file, perhaps adding name attribute to it will help.

Regards,

/Q

#146631
Mar 20, 2016 0:48
Vote:
 

Hi

Thanks for your quick reply. I'm using a filestream to pick up the file directly from the file system. As mentioned in my post I'm using the exact sample code off World that shows a sample request of submitting the file. The code from world that I'm using is below:

using (var client = new HttpClient())
{
    client.BaseAddress = new Uri("https://mysite.com/");
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    var content = new MultipartFormDataContent();
    var filestream = new FileStream(path, FileMode.Open);
    content.Add(new StreamContent(filestream), "file", "Catalog.zip");
    var response = client.PostAsync("/episerverapi/commerce/import/catalog", content).Result;
    if (response.StatusCode == HttpStatusCode.OK)
    {
        var returnString = response.Content.ReadAsStringAsync().Result;
        returnString = returnString.Replace("\"", "");
        Guid taskId = Guid.Empty;
        Guid.TryParse(returnString, out taskId);
    }
}

I have tried using this code from a console application as well as from just a basic webforms page. I get the same exception from both. I've also tried changing the contents of the Catalog.xml and re-zipping etc. Is this code the correct way of calling the service? This was taken from http://world.episerver.com/documentation/Items/Episerver-Service-API/Using-bulk-import-and-export-methods/Using-the-catalog-service/

Thanks for your help,

Damo

#146632
Mar 20, 2016 3:01
Vote:
 

Hi,

Shouldn't this line

var filestream = new FileStream(path, FileMode.Open);



be this:

var filestream = new FileStream(path, FileMode.Open, FileAccess.Read);

?

/Q

#146634
Edited, Mar 20, 2016 7:11
Vote:
 

Hi Quan,

With and without the access parameter I get the same error. I tried both. Do you have any sample code with the catalog import working? Since my post I've tried a few different ways to send the post but I still get the same error message.

Thanks,

Damien

#146637
Mar 20, 2016 11:05
Vote:
 

Hi,

No, I don't have anything else. The code is supposed to work with other sites - I haven't heard issues related to it.

How big is your catalog.zip btw? Is there any chance it's more than 4 MB?

/Q

#146638
Mar 20, 2016 11:54
Vote:
 

Ye old httpruntime max limit of bytes :) 

I wonder how many developer life times has been spent on that one overall...

#146645
Mar 20, 2016 16:43
Vote:
 

So I hope you problem is solved then?

/Q

#146646
Edited, Mar 20, 2016 17:30
Vote:
 

Hi Guys,

No I haven't resolved the issue as yet. I followed the setup guide for the service API so have already set the httpruntime attributes as well as the <system.webserver> attributes as well.

I'm probably at the stage where I'll need to log a support ticket now. Last night I also tried it from the Quicksilver demo project. I added the EPiServer.ServiceAPI.Commerce nuget package to the Commerce Manager. Then I setup a simple console application running the code above but I still got the same error.

Regarding the catalog zip file I updated it to almost contain nothing in it just to try and get successful post. It just contains the required tags with one product in it. The size of the zip is only 10KB. So size shouldn't be a problem.

Kind of out of ideas now as to what is causing this.

Thanks,

Damo 

#146647
Mar 21, 2016 0:30
Vote:
 

Hi,

You can always contact our support services. Our developer supports there can diagnose the problem easier if they have all the information in place.

Regards,

/Q

#146655
Mar 21, 2016 8:35
Vote:
 

Hi Quan,

Yes I'm going to log a support ticket. Thanks anyway for your help.

Regards,

Damien

#146717
Mar 21, 2016 23:22
Vote:
 

Hi Damien,

A quick google suggests that this is a ASP.net problem and might be solved by adding a newline at the end of the document.

http://stackoverflow.com/questions/13770536/asp-net-web-api-unexpected-end-of-mime-multi-part-stream-when-uploading-from-fl

Could you upload the file you used?

#146724
Mar 22, 2016 8:20
Vote:
 

Hi Toni,

Thanks for your post. I also came across this post during my troubleshooting. I also tried adding a newline to the end of the file by converting the file to a memory stream and then adding the new line and sending the memory stream through to the service API. This still returned the same error. The code I used I took from a comment on that stackoverflow post and is shown below.

Stream reqStream = Request.Content.ReadAsStreamAsync().Result;
        MemoryStream tempStream = new MemoryStream();
        reqStream.CopyTo(tempStream);



        tempStream.Seek(0, SeekOrigin.End);
        StreamWriter writer = new StreamWriter(tempStream);
        writer.WriteLine();
        writer.Flush();
        tempStream.Position = 0;

The zip file I'm using is quite basic and just has a test node and test product. I've shared it from my onedrive account which you can download from https://onedrive.live.com/redir?resid=6ED8BBB6B90803D2!20027&authkey=!AL2-5CyffXifeeE&ithint=folder%2czip

Thanks,

Damien

#146763
Mar 23, 2016 1:57
Vote:
 

Hi Damien,

Using EPiServer.ServiceApi.Client I can import your catalog in both Seagull, Quicksilver FRONT-sites.

But cannot import that on Commerce Manager.

So you can try again with Commerce site (not Manager site).

#146790
Mar 24, 2016 9:40
Vote:
 

Hi David,

Thanks for the information you've posted. I can verify that the bulk catalog import does work from the CMS and Commerce site.

So for anyone looking at using the Service API you should ONLY add the Service API to either the CMS site or commerce site. Not exactly sure what the issue is when adding it to the Commerce Manager but it doesn't work.

Thanks for helping me out with this guys.

Regards,

Damien

#146832
Mar 29, 2016 2:33
Vote:
 

Hi,

The document here stated that you should only install ServiceAPI to your Episerver based solution - either Commerce Sample or your actual solution: http://world.episerver.com/documentation/Items/Episerver-Service-API/Configuration-and-overview/Setting-up-EPiServerServiceApi/

We'll make it clear that we do not support install on Commerce Manager.

Regards,

/Q

#146833
Mar 29, 2016 5:42
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.