1

I am trying to upload a file to Google Cloud Storage using the signed url generated by the backend server it gives this error

SignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.PUT
multipart/form-data; boundary=50b17d2b-3095-4762-b93f-fa87bbe1c7bd
1926666331
/bucket_name/r1m767lcbtxnuu34hu9klrljf65q</StringToSign></Error>

i am using okhttp put request with multipart to upload the file like this

private fun directUpload(signedUrl: String, file: File) {
    try {
        val requestBody: RequestBody = RequestBody.create(
            file.getMimeType().toMediaTypeOrNull(),
            file
        )
        val request: Request = Request.Builder().url(signedUrl).put(requestBody)
            .build()
        val client = OkHttpClient()
        val response: Response = client.newCall(request).execute()
        if (response.isSuccessful) {
            response.toString()
            Log.d("Response_Direct_Upload", "FileUploaded")
        } else {
            Log.d("Response_Direct_Upload", response.body?.string().toString())
        }
    } catch (ex: Exception) {
        Log.d("Response_Direct_Upload", "FileUploadFailedException")
    }
}

The signed url generated by server looks like this

https://storage.googleapis.com/bucket_name/r1m767lcbtxnuu34hu9klrljf65q?GoogleAccessId=***************************&Expires=1926666331&Signature=yZmRFP%2BrvtsSy8AX%2F1eug2GN0wn%2BcrZVdHpICV5e%2F6ww0ioNusnEvk8G1u9oGmm3tE0XFr5rpiZ2q3hZ0%2BWx7dcOJlX95arXl1tiqV3p7ZO5qhRr1ZE3JkU1reNZF1yrQQVJiTgBy5mQTtXbWolAKbeo3JITY6ah3AMy%2FbpuGMpwr3vaNUM8HcbqOjPC%2FeWUrqGK3G57SKhz35OX6FK4SEAGNVauM7568L%2FT9h8DJLLr5QiyUgHXqNQjlBFuedI9CXaPthB3A086aDETNWhwtAS1h5vSGFTEy36thv6subXJZwC2vRNUfSEZxGA9hv0upwovJOVLsetipeIhBiXNJQ%3D%3D

  • Is it possible that it expired? Can you show how you created this signed URL? – vitooh Jan 21 '21 at 07:49
  • no its not expiring as it shows a different error if the link gets expired The signed url is created by the Rails Backend using the active storage library i am sending the meta data of file to the backend api to get the signed url – Salman Shakeel Jan 21 '21 at 11:36

0 Answers0