You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
verifyDirectFileUpload always returns false even when upload succeeds #2517
I get an upload description and my client uploads a file to GCP Storage. If I look in the dev console, I can see that the file correctly uploaded to the right bucket.
However, when I use the same upload description and call verifyDirectFileUpload, the response is always false. There is no error message or exception.
I don't want to just ignore the return value -- what could cause this problem?
The Serverpod code that checks if an upload succeeded is simply:
so I assume a false response means that GCP is returning a status code other than 200. However this is the production server, so I can't just set a breakpoint here to check it.
It is quite urgent that I get this fixed, since I'm trying to push out my 1.0 release -- would appreciate any help with this. Thanks!
Reacted by Olivier Melcher, Koen Van Looveren, kerridge and Stephan E.G. Veenstra
Reacted by Olivier Melcher, Koen Van Looveren and kerridge
I added a debug statement to Serverpod, and headObject is returning status code 400 (Bad Request).
I verified my HMACAccessKeyId and HMACSecretKey are correct. I even re-generated these, replaced them in passwords.yaml, updated the GitHub secrets, re-deployed my server, and yet this didn't fix the problem.
The path parameter should be correct -- I am using paths without an initial /, as the docs suggest for S3 compatibility (there is no mention of this being a problem on GCP, but I assume this should work, and at least not give a 400 error). (The Cloud Console shows the paths starting with a slash, however.)
I suspect that Serverpod is actually sending a badly-formed request to Google (and maybe they changed something recently that broke these requests...).
I tried just ignoring the response from verifyDirectFileUpload as a temporary workaround, but then getPublicUrl returns null, so basically I can't bypass this issue. It's a showstopper for my 1.0 release.
Have you tried this with a local server? That may be way easier to debug.
I ran through the upload flow a few months back, and everything was working correctly for me back then. Are you sure your server instance have access to the bucket? There may be some incorrect permissions that prevents Serverpod from accessing it.
I will check the permissions (no idea how, but I'll look into it). Whatever is there is just the Terraform default though.
I need to find a solution urgently, because I have to launch in the next 1-2 days. I may have to use another storage provider, or write my own code for GCP, if I can't figure this out. I just assumed this would work given that all the other GCP stuff is now working.
Rather than using the weird S3 compatibility layer for GCP, why not switch to using the "official" (but not yet declared stable) API from labs.dart.dev:
OK, I have an update on the 400 error. Google Cloud Storage is returning the following response to _doSignedHeadRequest, called by headObject, called by GoogleCloudStorage.fileExists:
<?xml version='1.0' encoding='UTF-8'?>
<Error>
<Code>MalformedSecurityHeader</Code>
<Message>Invalid argument.</Message>
<Details>Your request has a malformed header. Header was included in signedheaders, but not in the request.</Details>
<ParameterName>x-amz-security-token</ParameterName>
</Error>
However, if I just do a regular GET or HEAD request on the URL, without these security headers, I get the correct file content and headers. So this request does not even need to be signed, given the default permissions set up by Terraform.
I removed the signing of GET and HEAD requests in #2523, and the problem is now resolved for (verifyDirectFileUpload returns true, and getPublicUrl now returns the correct URL).
However I still have the same error for DELETE requests. For now I'm going to just live with the fact that files can be uploaded but never deleted, but this needs to be fixed too.
Based on the error message in the previous comment, do all the security headers also have to be included as URL query parameters?
I also get a 400 status code when calling verifyDirectFileUpload or retrieveFile. The body is empty on head requests, but get requests return the following:
<?xml version='1.0' encoding='UTF-8'?>
<Error>
<Code>MalformedSecurityHeader</Code>
<Message>Invalid argument.</Message>
<Details>
Your request has a malformed header. Header was included in signedheaders, but not in the request.
</Details>
<ParameterName>x-amz-security-token</ParameterName>
</Error>
I am able to generate an upload description, and upload a file with the FileUploader. My HMAC credentials are correct. It happens with both public and private storageId. I created the buckets manually following the docs and am running the server locally.
@olivoil yep, that's exactly what I was running into.
@vlidholt something badly needs fixing here, this was a showstopper for my release, and even with my workaround of disabling signing for GET requests, users can upload files but not delete them, so I need a solution fairly quickly or I'll be hosting a lot of orphaned files.
I haven't tested extensively yet, but createDirectFileUploadDescription and verifyDirectFileUpload both seem to work with this.
Nice work, I started building exactly the same thing, but eventually gave up and decided to hack together a solution for the existing S3 compatibility API.
Ultimately native Google Cloud API support needs to exist (working with Google Cloud Storage through the S3 API is 👎), so you should put together a proper PR around this -- it looks great to me!
I can test it a bit more and create a PR. Some considerations with this approach:
The gcloud dart sdk does not implement pre-signed urls out of the box - see outstanding issue - so the signing logic would be part of serverpod
It uses a service account rather than HMAC keys. If going this way, it may be good to update the site documentation
It expands the definitions of UploadDescription by adding httpMethod and headers and using them in FileUploader. I think that makes sense since when using signed urls, the headers must match the headers the url was signed with
It sets the x-goog-acl header to public-read if the storage is configured as public to make files accessible publicly. The header is not set on storages configured as private, so the files are not accessible publicly.
@olivoil I'm looking into the bucket implementation right now and found your implementation, my personal goal was to add management of metadata. But I think your implementation here looks very good and makes the entire integration with GCP pretty solid.
Would love if you opened a PR, I could also make the final adjustments if you don't mind, would like to have some tests setup around this too.
I just ran into this problem as well. Both the verifyDirectFileUpload and getPublicUrl don't work.
The first always returns false, and the second returns null.
I just ran into this problem as well. Both the verifyDirectFileUpload and getPublicUrl don't work.
The first always returns false, and the second returns null.
@SEGVeenstra Does this still happen on the latest Serverpod? We have completely revamped the storage packages on version 3.4.0 and added an extensive battery of tests. Now we have also a native GCP storage that is fully tested if you want to try.
I just ran into this problem as well. Both the verifyDirectFileUpload and getPublicUrl don't work.
The first always returns false, and the second returns null.
@SEGVeenstra Does this still happen on the latest Serverpod? We have completely revamped the storage packages on version 3.4.0 and added an extensive battery of tests. Now we have also a native GCP storage that is fully tested if you want to try.
I was using Oli's fix until 3.4 (now I'm using 3.4.5 without issues).
One note — getPublicUrl still returns null for private buckets, so if you need to serve private files you'll need to generate signed GET URLs yourself (the signing infrastructure is in the package but not exposed by default). Not 100% if that's an intended gap.
@studioaugustus Good to hear it is resolved. Regarding getPublicUrl - it is for public urls only, but you are not the only one to request this (see #4848, #4806). It is not on the immediate roadmap, but we will definitely return to this.
I'll close this issue as resolved. I consider the follow-up issue regarding private urls is covered by #4848.
I just ran into this problem as well. Both the verifyDirectFileUpload and getPublicUrl don't work.
The first always returns false, and the second returns null.
@SEGVeenstra Does this still happen on the latest Serverpod? We have completely revamped the storage packages on version 3.4.0 and added an extensive battery of tests. Now we have also a native GCP storage that is fully tested if you want to try.
Glad to hear this!
I have not yet been able to update my project. Hopefully I'll get to working on the project again somewhere this month.
Activity
lukehutch commentedon Jul 21, 2024
I added a debug statement to Serverpod, and
headObjectis returning status code 400 (Bad Request).I verified my
HMACAccessKeyIdandHMACSecretKeyare correct. I even re-generated these, replaced them inpasswords.yaml, updated the GitHub secrets, re-deployed my server, and yet this didn't fix the problem.The
pathparameter should be correct -- I am using paths without an initial/, as the docs suggest for S3 compatibility (there is no mention of this being a problem on GCP, but I assume this should work, and at least not give a 400 error). (The Cloud Console shows the paths starting with a slash, however.)I suspect that Serverpod is actually sending a badly-formed request to Google (and maybe they changed something recently that broke these requests...).
I tried just ignoring the response from
verifyDirectFileUploadas a temporary workaround, but thengetPublicUrlreturnsnull, so basically I can't bypass this issue. It's a showstopper for my 1.0 release.vlidholt commentedon Jul 22, 2024
Have you tried this with a local server? That may be way easier to debug.
I ran through the upload flow a few months back, and everything was working correctly for me back then. Are you sure your server instance have access to the bucket? There may be some incorrect permissions that prevents Serverpod from accessing it.
lukehutch commentedon Jul 22, 2024
Yes, it works with a local server.
I will check the permissions (no idea how, but I'll look into it). Whatever is there is just the Terraform default though.
I need to find a solution urgently, because I have to launch in the next 1-2 days. I may have to use another storage provider, or write my own code for GCP, if I can't figure this out. I just assumed this would work given that all the other GCP stuff is now working.
lukehutch commentedon Jul 22, 2024
@vlidholt This is what I'm seeing under Permissions:
Looks reasonable...
lukehutch commentedon Jul 22, 2024
Rather than using the weird S3 compatibility layer for GCP, why not switch to using the "official" (but not yet declared stable) API from labs.dart.dev:
https://pub.dev/packages/gcloud
and/or
https://pub.dev/packages/googleapis
I tried implementing a
GoogleCloudStorageNativeusing these:However, I could not figure out
createDirectFileUploadDescription.Refs:
lukehutch commentedon Jul 22, 2024
OK, I have an update on the
400error. Google Cloud Storage is returning the following response to_doSignedHeadRequest, called byheadObject, called byGoogleCloudStorage.fileExists:However, if I just do a regular GET or HEAD request on the URL, without these security headers, I get the correct file content and headers. So this request does not even need to be signed, given the default permissions set up by Terraform.
lukehutch commentedon Jul 22, 2024
I removed the signing of GET and HEAD requests in #2523, and the problem is now resolved for (
verifyDirectFileUploadreturnstrue, andgetPublicUrlnow returns the correct URL).However I still have the same error for DELETE requests. For now I'm going to just live with the fact that files can be uploaded but never deleted, but this needs to be fixed too.
Based on the error message in the previous comment, do all the security headers also have to be included as URL query parameters?
vlidholt commentedon Jul 23, 2024
I think your solution may only work for public files though? If they are private, authentication will likely be needed.
lukehutch commentedon Jul 23, 2024
Probably, but I never understood what the purpose of private files was. I don't recall seeing a good explanation of that in the docs.
As I mentioned, deletion will still require fixing the signing, so I guess once that's done, the other request types could also be signed again.
olivoil commentedon Aug 12, 2024
I also get a 400 status code when calling
verifyDirectFileUploadorretrieveFile. The body is empty onheadrequests, butgetrequests return the following:I am able to generate an upload description, and upload a file with the
FileUploader. My HMAC credentials are correct. It happens with both public and private storageId. I created the buckets manually following the docs and am running the server locally.lukehutch commentedon Aug 12, 2024
@olivoil yep, that's exactly what I was running into.
@vlidholt something badly needs fixing here, this was a showstopper for my release, and even with my workaround of disabling signing for GET requests, users can upload files but not delete them, so I need a solution fairly quickly or I'll be hosting a lot of orphaned files.
olivoil commentedon Aug 12, 2024
@lukehutch @vlidholt In case it helps, I'm doing this in the meantime: https://gist.github.com/olivoil/36a69cf37f54d3a009540202cc413827
I haven't tested extensively yet, but
createDirectFileUploadDescriptionandverifyDirectFileUploadboth seem to work with this.lukehutch commentedon Aug 12, 2024
Nice work, I started building exactly the same thing, but eventually gave up and decided to hack together a solution for the existing S3 compatibility API.
Ultimately native Google Cloud API support needs to exist (working with Google Cloud Storage through the S3 API is 👎), so you should put together a proper PR around this -- it looks great to me!
olivoil commentedon Aug 13, 2024
I can test it a bit more and create a PR. Some considerations with this approach:
UploadDescriptionby addinghttpMethodandheadersand using them inFileUploader. I think that makes sense since when using signed urls, the headers must match the headers the url was signed withx-goog-aclheader topublic-readif the storage is configured aspublicto make files accessible publicly. The header is not set on storages configured as private, so the files are not accessible publicly.@vlidholt would you be open to a PR?
Isakdl commentedon Aug 30, 2024
@olivoil I'm looking into the bucket implementation right now and found your implementation, my personal goal was to add management of metadata. But I think your implementation here looks very good and makes the entire integration with GCP pretty solid.
Would love if you opened a PR, I could also make the final adjustments if you don't mind, would like to have some tests setup around this too.
spaghettigus commentedon May 15, 2025
Hey, I was curious if there was an update on the roadmap progress. If we are trying to test some file upload features in our cloud setup should we opt to use olivoil's fix (https://gist.github.com/olivoil/36a69cf37f54d3a009540202cc413827)?
Please let me know. Thanks!
SEGVeenstra commentedon Mar 19, 2026
I just ran into this problem as well. Both the
verifyDirectFileUploadandgetPublicUrldon't work.The first always returns false, and the second returns null.
marcelomendoncasoares commentedon Apr 8, 2026
@SEGVeenstra Does this still happen on the latest Serverpod? We have completely revamped the storage packages on version 3.4.0 and added an extensive battery of tests. Now we have also a native GCP storage that is fully tested if you want to try.
spaghettigus commentedon Apr 8, 2026
I was using Oli's fix until 3.4 (now I'm using 3.4.5 without issues).
One note — getPublicUrl still returns null for private buckets, so if you need to serve private files you'll need to generate signed GET URLs yourself (the signing infrastructure is in the package but not exposed by default). Not 100% if that's an intended gap.
nielsenko commentedon Apr 9, 2026
@studioaugustus Good to hear it is resolved. Regarding
getPublicUrl- it is for public urls only, but you are not the only one to request this (see #4848, #4806). It is not on the immediate roadmap, but we will definitely return to this.I'll close this issue as resolved. I consider the follow-up issue regarding private urls is covered by #4848.
SEGVeenstra commentedon Apr 10, 2026
Glad to hear this!
I have not yet been able to update my project. Hopefully I'll get to working on the project again somewhere this month.