https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • f

    ForwardMotion

    04/21/2023, 6:59 AM
    i think i have it all wrong
  • i

    ikausik

    04/21/2023, 7:02 AM
    @Skye how to use googleapis for google sheets on workers?
  • h

    HardAtWork

    04/21/2023, 7:04 AM
    Try ```ts import { nanoid } from "nanoid"; export default { async email(message, env, ctx) { await env.BUCKET.put(nanoid(), message.raw, { customMetadata: { from: message.from, to: message.to, headers: Object.fromEntries(message.headers.entries()) }); } } ```The
    nanoid
    import is just there to ensure that you can't overwrite an email by sending another with the same subject.
  • h

    HardAtWork

    04/21/2023, 7:05 AM
    Please don't just ping people for help. If people are able/willing to help you, they will.
  • i

    ikausik

    04/21/2023, 7:09 AM
    👍
  • f

    ForwardMotion

    04/21/2023, 7:09 AM
    should i have this env varible set up like this?
  • f

    ForwardMotion

    04/21/2023, 7:12 AM
    getting this error
    Copy code
    Uncaught SyntaxError: Cannot use import statement outside a module at worker.js:1 (Code: 10021)
  • h

    HardAtWork

    04/21/2023, 7:12 AM
    Yup, though note you can call the binding whatever you want, I just called it
    BUCKET
    for simplicity's sake.
  • h

    HardAtWork

    04/21/2023, 7:13 AM
    It has to be bundled first. This code should "just work":
    Copy code
    js
    var o=(r=21)=>crypto.getRandomValues(new Uint8Array(r)).reduce((t,e)=>(e&=63,e<36?t+=e.toString(36):e<62?t+=(e-26).toString(36).toUpperCase():e>62?t+="-":t+="_",t),"");var u={async email(r,t,e){await t.BUCKET.put(o(),r.raw,{customMetadata:{from:r.from,to:r.to,headers:Object.fromEntries(r.headers.entries())}})}};export{u as default};
  • h

    HardAtWork

    04/21/2023, 7:13 AM
    This code is the same as the above, just with
    nanoid
    inlined.
  • h

    HardAtWork

    04/21/2023, 7:14 AM
    Again though, you don't need
    nanoid
    , I just added it to prevent collisions. If you have your own way of doing so, then you can omit
    nanoid
    entirely
  • f

    ForwardMotion

    04/21/2023, 7:14 AM
    just to check my understanding, naniod is just being used to generate a random key so that it avoids duplicates(or worse) and really anything can be set as the key?
  • h

    HardAtWork

    04/21/2023, 7:15 AM
    Yes. Any string should function as a key, I just used it to ensure that you couldn't overwrite a stored email by sending a different one with the same subject value.
  • f

    ForwardMotion

    04/21/2023, 7:22 AM
    okay great i am learning. The worker is failing, but i don't know how to check why?
  • f

    ForwardMotion

    04/21/2023, 7:22 AM
  • f

    ForwardMotion

    04/21/2023, 7:24 AM
    on the code editor it says "Email Trigger not available to this workers" in the console. i tried in the worker opening a log stream but nothing was logged?
  • f

    ForwardMotion

    04/21/2023, 7:31 AM
    okay got the log
    Copy code
    "exceptions": [
        {
          "name": "TypeError",
          "message": "Provided readable stream must have a known length (request/response body or readable half of FixedLengthStream)",
          "timestamp": 1682062251076
        }
      ],
  • f

    ForwardMotion

    04/21/2023, 7:38 AM
    okay so i got it uploading but the contents are empty, almost there lol
  • f

    ForwardMotion

    04/21/2023, 7:38 AM
    thank you for putting me on track and getting me here!
  • f

    ForwardMotion

    04/21/2023, 7:39 AM
    gonna get some sleep and tackle this tommorow, just a bit more to figure out and ill have it working
  • f

    ForwardMotion

    04/21/2023, 7:39 AM
    with much help thank you
  • d

    dave

    04/21/2023, 3:22 PM
    How does Smart Placement work if it connects to a backend that is latency based between two very different locations?
  • k

    kian

    04/21/2023, 3:24 PM
    Think of it like Argo - it'll figure out what the best place is to reduce RTT to the subrequest origins.
  • k

    kian

    04/21/2023, 3:24 PM
    If it's not going to be able to help, it won't do anything
  • d

    dave

    04/21/2023, 3:25 PM
    I'm worried that my EU users will end up getting pushed to US backends though
  • k

    kian

    04/21/2023, 3:26 PM
    As in you have 1 Worker which decides which origin to request based on user location?
  • d

    dave

    04/21/2023, 3:26 PM
    yes
  • d

    dave

    04/21/2023, 3:26 PM
    well
  • d

    dave

    04/21/2023, 3:27 PM
    it decides based on latency to the origin
  • d

    dave

    04/21/2023, 3:27 PM
    I do 2 identical requests to the same backend (but in different regions). Whichever returns faster is the one we use for the rest of the Worker
1...240724082409...2509Latest