0

i have a wierd problem i cant seem to get around.

I have a gzip file that i can upload to my Firebase Storage bucket easily using the gsutil tool:

gsutil -h "Content-Encoding:gzip" -h "Content-Type:application/json" cp myGzipFileWithoutGzExtension.json gs://my-bucket-name.appspot.com

The file starts as a normal json file, compressed its 32kb.

Now i want to do the same in my c# console app. But when i upload to the same url, Firebase Storage removes compression and the file ends up around 400kb (removed whitespaces etc) ?!?!

var url = "https://firebasestorage.googleapis.com/v0/b/my-bucket-name.appspot.com/o?name=myGzipFileWithoutGzExtension.json"
var stream = File.Open(@"C:\temp\myGzipFileWithoutGzExtension.json ", FileMode.Open);

using (var client = new HttpClient())
{
    var streamContent = new StreamContent(stream);
    streamContent.Headers.Add("Content-Encoding", "gzip");
    streamContent.Headers.Add("Content-Type", "application/json");
    streamContent.Headers.ContentLength = stream.Length;

    var request = new HttpRequestMessage(HttpMethod.Post, url)
    {
        Content = streamContent,
    };

    var response = await client.SendAsync(request, cancellationToken).ConfigureAwait(false);
    var responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}

Am i going about the wrong way doing this? I just want to upload my 32kb json (gzip) file, and have the correct Content-Encoding on it so that the browser will handle the decompression (works when i do it with the gsutil uploaded file, so its working as expected)

Swift
  • 166
  • 2
  • 16
  • Run a capture tool like Fiddler and compare the text of the working & non-working requests. – Alex K. Feb 02 '17 at 15:22
  • Any chance you could explain how i setup fiddler to listen to my cmd prompt gsutil command? I know how to use fiddler for browser, but since its not capturing my gsutil traffic, even though i setup winhttp to go via fiddler proxy, im not sure how to capture the post netsh winhttp set proxy 127.0.0.1:8888 – Swift Feb 03 '17 at 10:29
  • I don't know anything about gsutil perhaps it has its own proxy settings/command line? If Fiddler does not work Wireshark is an alternative that will work without being a proxy although you will have to mess around to get it to display decrypted https/tls. – Alex K. Feb 03 '17 at 10:32
  • Did you end up solving this? I'm having the exact same issue. – Tsury Mar 30 '18 at 21:45

0 Answers0