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

    dkfdkdodkms

    05/15/2023, 3:38 PM
    and even if i use a smaller file, and the first upload succeeds, a subsequent call (with no post data) will fail
  • d

    dkfdkdodkms

    05/15/2023, 3:39 PM
    (pending state)
  • s

    Skye

    05/15/2023, 3:39 PM
    I can't reproduce that
  • d

    dkfdkdodkms

    05/15/2023, 3:40 PM
    i believe that is because it really depends on how many bytes you're sending. i notice different behavior with different file sizes
  • d

    dkfdkdodkms

    05/15/2023, 3:41 PM
    yes, bugs can happen, but this is rather fundamental to cloudflare tech, and it is broken in both local and experimental
  • s

    Skye

    05/15/2023, 3:42 PM
    Both of which are powered by miniflare
  • d

    dkfdkdodkms

    05/15/2023, 3:42 PM
    also, i've tested on two machines (one intel mac, the other m2 mac), and a windows vm (all tested in chromium based browsers). using the same files, i get the same behavior
  • d

    dkfdkdodkms

    05/15/2023, 3:43 PM
    yes, but supported by cloudflare?
  • s

    sathoro

    05/15/2023, 3:43 PM
    do you have a repo so I can test it?
  • s

    Skye

    05/15/2023, 3:43 PM
    I more meant that the bug happening in two places still have the same underlying cause
  • d

    dkfdkdodkms

    05/15/2023, 3:44 PM
    i will create a repo
  • c

    Chaika

    05/15/2023, 3:45 PM
    If it helps, the code I put up on based on your original to test it is: https://cdn.discordapp.com/attachments/779390076219686943/1107695148021850184/worker.js
  • d

    dkfdkdodkms

    05/15/2023, 3:50 PM
    https://github.com/dkfdkdodkms/worker_upload_test
  • d

    dkfdkdodkms

    05/15/2023, 3:50 PM
    i included a test avi file
  • s

    sathoro

    05/15/2023, 3:53 PM
    this is working fine for me with 10mb and 50mb files
  • d

    dkfdkdodkms

    05/15/2023, 3:53 PM
    yes, the online one works fine for me
  • s

    sathoro

    05/15/2023, 3:53 PM
    it was hanging until I added an
    await request.text();
    to the top of the
    fetch
    handler
  • s

    sathoro

    05/15/2023, 3:53 PM
    no, not the online one
  • s

    sathoro

    05/15/2023, 3:53 PM
    the code
  • s

    sathoro

    05/15/2023, 3:53 PM
    running locally
  • s

    sathoro

    05/15/2023, 3:54 PM

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

  • s

    sathoro

    05/15/2023, 3:54 PM
    10mb then 50mb
  • s

    sathoro

    05/15/2023, 3:54 PM
    using your AVI file

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

  • d

    dkfdkdodkms

    05/15/2023, 3:54 PM
    let me look at the code this is based off. i believe this also fails when consuming the body stream, which is how i found this issue
  • s

    sathoro

    05/15/2023, 3:55 PM
    Copy code
    js
    const HTML = `<!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('/', {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>`;
    
    export default {
      async fetch(request, env) {
        await request.text();
        if (request.method == "GET") {
          return new Response(HTML, { headers: { "content-type": "text/html" } });
        }
        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;
      },
    };
  • s

    sathoro

    05/15/2023, 3:55 PM
    that is the worker using
    --local
  • s

    sathoro

    05/15/2023, 3:56 PM
    without
    await request.text();
    it was hanging, but no errors
  • d

    dkfdkdodkms

    05/15/2023, 3:56 PM
    the reason why i didn't include something like await request.text() was just to make the example as simple as possible, but the code the example is based off does try to consume the body
  • s

    sathoro

    05/15/2023, 3:56 PM
    well even without it I don't get an error
  • d

    dkfdkdodkms

    05/15/2023, 3:57 PM
    with --local it will hang. with --experimental local it will error
1...246524662467...2509Latest