upload to google cloud storage signed url with javascript

前端 未结 2 2060
野的像风
野的像风 2021-02-13 12:53

With the following code I\'m able to upload to my publicly writable bucket in google cloud storage. (allUsers has write permission). However If the bucket isn\'t publicly writab

相关标签:
2条回答
  • 2021-02-13 13:16

    I was implementing the same issue. The problem is with SignedURL. After correcting the signedurl the upload worked like a charm.

    As I was using php. Below is the code for generating signed urls.

    private function createSignedUrl($objectName, $bucketName, $key, $serviceEmailAddress, $method = 'GET', $duration = 600)
    {
        $expires = time() + $duration;
    
    // Line breaks are important!
    $toSign = (
        $method . "\n" .
        /* Content-MD5 */ "\n" .
        /* Content Type */ "\n" .
        $expires . "\n" .
        $objectName
    );
    $signature = urlencode(base64_encode(JWT::encode($toSign, $key, 'HS256')));
    return array(
        'expires' => $expires,
        'accessid' => $serviceEmailAddress,
        'signature' => $signature,
    );
    }
    
    0 讨论(0)
  • 2021-02-13 13:27

    Use https://storage.googleapis.com as a host to compose the URL that points to the desired resource. You can choose between a few ways to construct your base URL. Here are some possible combinations.

    For reference, you can also check out a very simple snippet Python that could be helpful.

    Hope it helps.

    0 讨论(0)
提交回复
热议问题