googlecodelabs / photos-sharing

Code for the "Build a Photo Sharing app with Google Photos and Flutter" codelab
Apache License 2.0
98 stars 76 forks source link

Page7 question #14

Closed les-kasa-1010 closed 4 years ago

les-kasa-1010 commented 4 years ago

Do you need these lines?

    // Get the filename of the image
    final String filename = path.basename(image.path);

    // Set up the headers required for this request.
    final Map<String, String> headers = <String, String>{};
    headers.addAll(await _authHeaders);
    headers['Content-type'] = 'application/octet-stream';
    headers['X-Goog-Upload-Protocol'] = 'raw';
    headers['X-Goog-Upload-File-Name'] = filename;

Because you are using "await _authHeaders" for "headers" parameter, I don't think those lines are necessary.

jfschmakeit commented 4 years ago

Upload requests need some additional headers that are not required for other requests to the Google Photos Library API.

You can find out more in the developer guides here: https://developers.google.com/photos/library/guides/upload-media#uploading-bytes

denkasyanov commented 4 years ago

I had the same question while skimming through the codelab.

I think the problem in the codelab is that the request is made with await authHeaders instead of the headers variable that includes those additional headqers (line 15 in codelab or https://github.com/googlecodelabs/photos-sharing/blob/final/lib/photos_library_api/photos_library_api_client.dart#L165 in app repo).