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

    Skye

    02/19/2023, 1:51 PM
    if your file is called
    asd.pdf
    , that will be what's in
    key
  • m

    Mr.Kevin

    02/19/2023, 1:53 PM
    I uploaded file named
    SRS - english.pdf
    and get the key
    files/a-uYgM0r4crU6Lw1-yDIn/0000000000
  • s

    Skye

    02/19/2023, 1:54 PM
    That sounds like a library you're using might be renaming the file or something
  • m

    Mr.Kevin

    02/19/2023, 1:54 PM
    okay, thanks. let me check
  • s

    Skye

    02/19/2023, 1:58 PM
    Just tested -
    key
    is definitely the filename
    Copy code
    js
    export default {
      async fetch(request, env) {
        const { objects } = await env.R2.list();
        return Response.json(objects.map(x => x.key))
      }
    }
    The above code produced the following output, which is exactly what I'd expect
    Copy code
    json
    ["rank-cards/0.png","rank-cards/1.png","rank-cards/10.png","rank-cards/11.png","rank-cards/2.png","rank-cards/3.png","rank-cards/4.png","rank-cards/5.png","rank-cards/6.png","rank-cards/7.png","rank-cards/8.png","rank-cards/9.png"]
  • s

    Scheggia

    02/19/2023, 2:20 PM
    Does anyone know if somehow I can get images loaded even with masked url? For example, the domain pointing to the Bucket is
    cdn.domain.com
    and so the images are displayed as
    cdn.domain.com/images/myimage.png
    . Can I make those loaded through
    img.domain.com
    lead directly to the /images subfolder of the main domain, so
    img.domain.com/myimage.png
    ?
  • d

    Deleted User

    02/19/2023, 2:28 PM
    Probably Rewrite Rules https://developers.cloudflare.com/rules/transform/url-rewrite/create-dashboard/
  • d

    Deleted User

    02/19/2023, 2:29 PM
    although... You'd have to also bind the bucket to the
    img
    subdomain since rewrite rules rewrite on the same host
  • s

    Scheggia

    02/19/2023, 2:45 PM
    Thanks, but will it work even if the image is inside discord?
  • e

    Erisa | Support Engineer

    02/19/2023, 2:46 PM
    i dont see why not
  • e

    Erisa | Support Engineer

    02/19/2023, 2:47 PM
    svg is right, you want to - bind img.domain.com to the bucket also - create a rewrite rule to rewrite / to /images
  • s

    Scheggia

    02/19/2023, 2:48 PM
    I need to make sure that if on discord I send the url with the image (such as img.domain.com/myimage.png) it is loaded from cdn.domain.com/images/myimage.png
  • s

    Scheggia

    02/19/2023, 2:48 PM
    Ty, i'll try
  • e

    Erisa | Support Engineer

    02/19/2023, 2:48 PM
    discord just fetches the url from their servers, its no different to any other way of serving an image
  • m

    Mr.Kevin

    02/19/2023, 2:56 PM
    now I'm using uppy for uploading and it renamed the name do you have experience with uppy?
  • s

    Skye

    02/19/2023, 3:04 PM
    I do not unfortunately
  • s

    Scheggia

    02/19/2023, 3:04 PM
    I inserted as a condition
    Copy code
    (starts_with(http.request.full_uri, "https://img.mydomainhere.com/"))
    and Path > Rewrite to > Dynamic:
    Copy code
    concat("/i", http.request.uri.path)
    But it doesn't seem to be working... If I deactivate the rule and go to
    img.domain.com/i/myimage.png
    it works, then activating it and going to
    img.domain.com/myimage.png
    it returns 404 so it doesn't redirect correctly. I also cleared the browser cache and Cloudflare cache.
  • m

    Mr.Kevin

    02/19/2023, 3:05 PM
    Okay I see , THanks for your help
  • e

    Erisa | Support Engineer

    02/19/2023, 3:07 PM
    odd because I reproduced the same setup (though I used a Hostname match for the filter) and it worked In my case I used
    concat("/avatars", http.request.uri.path)
    on
    r2.erisa.uk
    and now

    ▾

    is returning the same as

    ▾

  • e

    Erisa | Support Engineer

    02/19/2023, 3:08 PM
  • s

    Scheggia

    02/19/2023, 3:09 PM
    Tysm, I'll take a closer look and try again
  • s

    Scheggia

    02/19/2023, 3:21 PM
    I recreated the rule from scratch by creating an images folder, if I go to

    ▾

    it works instead on

    ▾

    it doesn't. Rewrite is the same:
    concat("/images", http.request.uri.path)
  • s

    Skye

    02/19/2023, 3:22 PM
    Are you expecting it to change the hostname for you too?
  • s

    Skye

    02/19/2023, 3:23 PM
    Because at the moment that rule just adds
    /images
    to the start of the path and fetches it
  • e

    Erisa | Support Engineer

    02/19/2023, 3:23 PM
    both subdomains are mapped to the same R2 bucket
  • s

    Skye

    02/19/2023, 3:23 PM
    ah, that should be fine then
  • s

    Scheggia

    02/19/2023, 3:24 PM
    Yes
  • e

    Erisa | Support Engineer

    02/19/2023, 3:24 PM
    @Scheggia can you clear the cache for the entire zone?
  • e

    Erisa | Support Engineer

    02/19/2023, 3:24 PM
    because its intermittently working and not working for me, and when it doesnt work i get HIT cache status
  • s

    Scheggia

    02/19/2023, 3:25 PM
    Purged everything again (on scheggia.gg domain)
1...881882883...1050Latest