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

    Cyb3r-Jok3

    05/15/2023, 2:46 AM
    https://github.com/ffmpegwasm/ffmpeg.wasm/blob/master/src/node/fetchFile.js
    const fs = require('fs');
    fs
    isn't in workers
  • h

    harris

    05/15/2023, 2:46 AM
    My videos are stored on R2 so it'd be quite nice to find a way to clip them without needing to go to an external service and without switching over to Cloudflare Stream
  • c

    Cyb3r-Jok3

    05/15/2023, 2:47 AM
    You'd probably also run into the resource limits with workers
  • h

    harris

    05/15/2023, 2:47 AM
    oh, what are those set to?
  • h

    harris

    05/15/2023, 2:50 AM
    oh wow, they're quite tiny
  • c

    Cyb3r-Jok3

    05/15/2023, 2:50 AM
    Depends in your usage plan https://developers.cloudflare.com/workers/platform/pricing/#usage-models
  • h

    harris

    05/15/2023, 2:50 AM

    https://cdn.discordapp.com/attachments/779390076219686943/1107500278166585374/image.png▾

  • h

    harris

    05/15/2023, 2:51 AM
    i see, i guess i'll have to look at GCP or lambda then
  • d

    dave

    05/15/2023, 3:27 AM
    use a Worker to call a Lambda. https://github.com/aimoda/cloudflare-worker-to-aws-lambda-function-url-example
  • h

    harris

    05/15/2023, 3:27 AM
    why?
  • d

    dave

    05/15/2023, 3:28 AM
    you can do all of your biz logic in a Worker (way easier IMO), and then have a dumb Lambda.
  • h

    harris

    05/15/2023, 3:28 AM
    the main logic is here is mp4 url, and start end time, clip it and upload to bucket
  • h

    harris

    05/15/2023, 3:28 AM
    how would having a worker call that lambda help?
  • d

    dave

    05/15/2023, 4:16 AM
    do you plan on exposing this to the internet?
  • h

    harris

    05/15/2023, 4:17 AM
    no
  • d

    dave

    05/15/2023, 4:17 AM
    oh
  • h

    harris

    05/15/2023, 4:17 AM
    is for use only by the backend
  • h

    harris

    05/15/2023, 4:17 AM
    so would have locked down to that
  • a

    Akeldama

    05/15/2023, 8:25 AM
    Hello! I'm wondering if it's possible to create a worker with both a fetch and schedule function. If it is possible, would it be considered best practice to combine them into a single worker, or would it be better to create separate workers for the schedule and fetch methods?
  • d

    Dani Foldi

    05/15/2023, 8:27 AM
    You can define all handlers in a single worker, without any issues. I consider it a good practice, as the two can share code, but (bearing in mind the limited number of workers per account) keeping them separate is also fine
  • a

    Akeldama

    05/15/2023, 8:29 AM
    Thank you for the answer : )
  • s

    semicolondev

    05/15/2023, 11:18 AM
    Hello, can I use Cloudflare Workers with OpenAI Chat Server Sent Events? Are there any restrictions as such?
  • z

    zizi

    05/15/2023, 11:40 AM
    I think you can, cloudflare don't buffer response. SSE should working fine.
  • s

    sathoro

    05/15/2023, 11:58 AM
    yes, you can. it works very well. we do it in production at scale (https://koala.sh)
  • s

    sathoro

    05/15/2023, 12:03 PM
    it is a bit tricky if you want to properly parse the stream inside the worker itself like we need to do. I built some custom parsing and timeout handling based off this . good luck 😉 I would stick to parsing on the client if you can
  • d

    dkfdkdodkms

    05/15/2023, 1:58 PM
    There appears to be a significant issue with uploading files with POST. It works fine with small files (a hundred KB), but anything over 2 MB appears to be certain to fail. Also, if the file is a bit less, it may not cause that call to fail, but it will cause the next call to fail. By fail, I mean the request never completes (is stuck as "pending"). Attached is a barebones test case, which reproduces this issue. https://cdn.discordapp.com/attachments/779390076219686943/1107668370779799615/test.zip
  • s

    Skye

    05/15/2023, 1:59 PM
    Could you make it as a git repo or something easier to access? 🙂
  • d

    dkfdkdodkms

    05/15/2023, 2:00 PM
    Copy code
    export interface Env 
    {
        env:string; //"prod" or "dev"
    }
    
    export default 
    {
        async fetch(request:Request, env:Env, context:ExecutionContext):Promise<Response> 
        {
            let response = new Response('{}');
            response.headers.set('Access-Control-Allow-Headers', 'Content-Type, X-Json');    
            response.headers.set('Access-Control-Allow-Origin', '*');
            response.headers.set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS');
            response.headers.set('Access-Control-Max-Age', '86400');
            
            return response;        
        }
    };
  • d

    dkfdkdodkms

    05/15/2023, 2:01 PM
    Copy code
    <!DOCTYPE html>
    <html>
      <head>
        <title>File Upload Test</title>
      </head>
      <body>
        <h1>File Upload Test</h1>
        <form id="uploadForm">
          <input type="file" id="fileInput" name="file" />
          <button type="submit">Upload</button>
        </form>
    
        <script>
          document.getElementById('uploadForm').addEventListener('submit', function (event) 
          {
            event.preventDefault();
            
            var fileInput = document.getElementById('fileInput');
            var file = fileInput.files[0];
    
            var formData = new FormData();
            formData.append('file', file);
    
            fetch('http://127.0.0.1:8081/', {method:'POST', body:formData}).then(response => 
            {
                if (response.ok) alert('File uploaded successfully.');
                else alert('Error uploading file.');
            }).catch(error => 
            {
                console.error('Error:', error);
            });
          });
        </script>
      </body>
    </html>
  • d

    dkfdkdodkms

    05/15/2023, 2:01 PM
    that's it
1...246224632464...2509Latest