0

I am creating a shipment from Amazon and getting a proper response file back.

But I need to get a carrier label in PNG format which is not so bad but I'm having issues with the Gzip process.

The Developer Guide from Amazon states:

  1. Decode the Base64-encoded string.
  2. Save the decoded string with a .gzip extension
  3. Extract the PDF/PNG or ZPL File from the GZIP File.

So Step 1 and 2 I kind of did but the file in step 3 isn't a proper PNG or similar.

Here is my code:

static void Main(string[] args)
{
    byte[] data = Convert.FromBase64String("Base64 String");

    using (FileStream fs = new FileStream(@"G:\Label.PNG.gzip", FileMode.CreateNew))
    {
        using (GZipStream zipStream = new GZipStream(fs, CompressionMode.Compress, false))
        {
            zipStream.Write(data, 0, data.Length);
        }
    }
}
dark4521
  • 1
  • 1

1 Answers1

0

Solved it:

var byteStream = Convert.FromBase64String("Base64 String");

        Image image = null;

        using (MemoryStream memoryStream = new MemoryStream(byteStream))
        {
            using (GZipStream gzip = new GZipStream(memoryStream,CompressionMode.Decompress))
            {
                image = Image.FromStream(gzip);
            }
        }
        image.RotateFlip(RotateFlipType.RotateNoneFlipNone);

        image.Save(@"G:\label123.png");
dark4521
  • 1
  • 1