https://discord.cloudflare.com logo
Join Discord
Powered by
# r2
  • w

    Waiiki

    03/31/2023, 9:26 PM
    still no work
  • w

    Waiiki

    03/31/2023, 9:27 PM
    Copy code
    uploadImageToR2: builder.mutation<any, cloudFlareUploadRequest>({
        query: (uploadRequest) => ({
          url: `${uploadRequest.preSignedUrl}`,
          method: "PUT",
          body: uploadRequest.file,
          headers: {
            "Origin": "http://localhost:3001",
            "Content-Type": uploadRequest.file.type 
          },
        }),
      
        transformResponse: (response: any, meta) => {
          console.log("Success");
          return response;
        },
        transformErrorResponse: (response, meta, arg) => {
          return {
            originalArg: arg,
            error: response,
          };
        },
      }),
    This seems correct to me
  • k

    kian

    03/31/2023, 9:39 PM
    You haven't added
    Content-Type
    as an allowed header
  • w

    Waiiki

    03/31/2023, 9:43 PM
    same result :/
  • w

    Waiiki

    03/31/2023, 9:43 PM
    Copy code
    access to fetch at ... from origin 'http://localhost:3001' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
  • w

    Waiiki

    03/31/2023, 9:44 PM
    also, is a presign url supposed to start with the bucket name? for example : https://test-bucket.accountid/etc
  • k

    kian

    03/31/2023, 9:45 PM
    You can use that or you can use
    accountid.r2.cloudflarestorage.com/bucketname/
  • w

    Waiiki

    03/31/2023, 9:45 PM
    so either should work? because yeah that's what they give in the example you linked the other day
  • w

    Waiiki

    03/31/2023, 9:46 PM
    but what is returned from the presign function is with the bucket name first
  • k

    kian

    03/31/2023, 9:49 PM
    How are you generating the presigned URL?
  • w

    Waiiki

    03/31/2023, 10:12 PM
    Copy code
    var credentials = new BasicAWSCredentials("accesskey",
                    "secretkey");
    
    
    
                _s3Client = new AmazonS3Client(credentials, new AmazonS3Config
                {
                    ServiceURL = $"https://accountid.r2.cloudflarestorage.com",
                   
                    
    
                });
  • w

    Waiiki

    03/31/2023, 10:12 PM
    Copy code
    public string GetPreSignedUrl(string bucketName, string keyName)
            {
    
                AWSConfigsS3.UseSignatureVersion4 = true;
                var request = new GetPreSignedUrlRequest
                {
                    BucketName = "test-bucket",
                    Key = keyName,
                    Verb = HttpVerb.PUT,
                    Expires = DateTime.Now.AddMinutes(45),
    
                    
                   
                };
    
                var url = _s3Client.GetPreSignedURL(request);
                return url;
            }
  • w

    Waiiki

    03/31/2023, 10:12 PM
    this is sent to my react app
  • w

    Waiiki

    03/31/2023, 10:13 PM
    obvi I replace the credentials and account id with real values
  • g

    gautam32

    03/31/2023, 11:47 PM
    Hi, will it be possible to rename buckets in the future? Currently, If i want to rename it i will have to copy all files to the new bucket.
  • k

    Karew

    04/01/2023, 12:57 AM
    On the R2 web interface, there doesn't seem to be any way to put prefixes in front of the file you're uploading unless you've already used that prefix before
  • k

    Karew

    04/01/2023, 5:12 AM
    Unlikely, you can’t even rename buckets on S3
  • k

    Karew

    04/01/2023, 5:12 AM
    The good news is copying to another bucket is very fast because you can use a server copy and not need to download the object
  • v

    Vitamin Protein

    04/01/2023, 8:08 AM
    then it ll cost / 1request .that was my whole purpose of caching
  • Access Object Expiry information from workers
    b

    buckett

    04/01/2023, 9:17 AM
    With object lifecycles (https://developers.cloudflare.com/r2/buckets/object-lifecycles/) is it possible to find out when a specific object is due to expire, so for example if I have a lifecycle policy that expires objects after 14 days, can I see a specific object is due to expire? I know I could calculate this based on the upload date, but then I'm having to keep my own calculations in-sync with the actual bucket policy. It would be really helpful to allow the
    R2ListOptions
    to accept an
    include
    value of
    expiry
    which then returned the expected expiry for each item in the response.
  • l

    Leo_C

    04/01/2023, 9:51 AM
    hi
  • l

    Leo_C

    04/01/2023, 9:51 AM
    How to solve cors issues caused by browser caching in Cloudflare?
  • e

    elithrar

    04/01/2023, 12:50 PM
    https://developers.cloudflare.com/r2/buckets/cors/
  • l

    Leo_C

    04/01/2023, 12:58 PM
    Thank you for your help. Yes, I have set up cross-domain in r2, but it is the browser cache that causes the cross-domain issue. The first request can be successful, but when the second request is directly retrieved from the browser cache, it will encounter cross-domain issues. I have looked up some information and found that it is necessary to set the request header "cache-control: no-cache" to solve this issue. However, I couldn't find a way to set this request header in Cloudflare.
  • e

    elithrar

    04/01/2023, 1:20 PM
    You can do this with a custom domain on R2 - https://developers.cloudflare.com/r2/buckets/public-buckets/ and https://developers.cloudflare.com/rules/transform/response-header-modification/
  • e

    elithrar

    04/01/2023, 1:21 PM
    However I’d love to see the actual console error you get + your CORS policy as this shouldn’t be necessary
  • l

    Leo_C

    04/01/2023, 3:37 PM
    I have found how to add response headers. The problem has been solved. Thank you so much.
  • c

    Crazy Rabbit

    04/01/2023, 5:04 PM
    How to get the content type from R2?
  • c

    Crazy Rabbit

    04/01/2023, 5:22 PM
    So now
    setCacheR2
    function will also append
    Content-Type
    header and return it in
    getCacheR2
    function.
  • c

    Crazy Rabbit

    04/01/2023, 5:23 PM
1...971972973...1050Latest