Closed mvanhalen closed 8 years ago
Hello!
I wrote a test which I've included below and have to say that it's working. The output can be found here: https://seamist.blob.core.windows.net/test/mvanhalen/test.png.
Are you sure that the stream contains valid data?
Regards, Kevin
[TestMethod]
public void GitHub_MvanHalenStreamIssue1_IsTrue()
{
var image = File.ReadAllBytes(TestData.LocalTestImage);
MemoryStream stream = new MemoryStream(image);
// Use a stream
var result = ResizeImage(stream, 100, 100, "test.png", "mvanhalen");
Assert.IsTrue(result.EndsWith("mvanhalen/test.png"));
}
public string ResizeImage(Stream input, int width, int height, string filename, string folder)
{
// Create a connection and client
var client = HelperFunctions.CreateWorkingClient();
string result = "";
var dataStore = new DataStore(
Settings.AzureAccount,
Settings.AzureKey,
Settings.AzureContainer, folder + "/" + filename);
dataStore.AddHeaders("Cache-Control", "max-age=2222");
using (MemoryStream ms = new MemoryStream())
{
input.Position = 0;
input.CopyTo(ms);
ms.Position = 0;
var response = client.OptimizeWait(ms.ToArray(), filename, new OptimizeUploadWaitRequest(dataStore)
{
ResizeImage = new ResizeImage
{
Width = width,
Height = height,
Strategy = Strategy.Auto
}
});
if (response.Result.StatusCode == HttpStatusCode.OK)
{
result = response.Result.Body.KrakedUrl;
// result = AzureURL + "/" + AzureContainer + "/" + folder + "/" + filename;
}
}
return result;
}
Thanks, Yeah, stream data looks fine, but I´ll test again with some other files. It feels like some kind of threading issue somehow like the process keeps waiting for something. I´ll let you know.
Sounds interesting. What’s the execution context of your application? A IIS application pool, a service or something else?
Sorry for the late reply. Many GitHub messages end up in my Spam folder.
It´s an ASP.Net MVC website I get the execution issue (like it never stops) when accessing the response object or something. In the end it will run as an Azure cloud service.
When running a test like you it works fine. So the execution context might be related to the issue. Not sure. It seems like the job is executed on Kraken side but accessing the response data leads to an issue. Weird right?
I just tested it with not accessing the response object and the code runs fine. It´s executed correctly and the file is added to the Azure Storage Blob. Does that make any sense to You?
No problem and thanks for providing the details. Yes, it does make sense; The response retrieval process is causing a deadlock.
using (var responseMessage = await _client.PostAsync(_krakenApiUrl + apiRequest.Uri, content, cancellationToken)
Is missing ConfigureAwait(false)
Bit sloppy from my side and therefore including a hosted test within the repository asap.
To solve your issue, I will create a new release within a couple of minutes.
New client available -> https://www.nuget.org/packages/kraken-net/1.1.1 or Install-Package kraken-net
Thanks a lot Kevin. Your prompt response is gold. I´ll test the new package and let you know.
The new update fixes the bug. Great work and thanks!
Hi,
great package. I have some image url functions working. But this snippet I cannot get to work. ` public string ResizeImage(Stream input,int width,int height,string filename,string folder) {
The stream contains data, any idea what I´m doing wrong?