Skip to content

chris-carrington/image-upload-prototype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Upload Prototype

Content Type

  • A content-type of multipart/form-data indicates that in the request body, each piece of data (form field, file upload, etc) contains its own section
  • The boundary is a unique delimiter (example: ------WebKitFormBoundaryECOAm72ObCFGjWIt) that separates different sections in the request body
  • When the server processes the request, it uses the boundary (which is provided in the request header content-type) to split the request body into sections
  • Example Header:
    content-type: multipart/form-data; boundary=----WebKitFormBoundaryECOAm72ObCFGjWIt
    
  • Example Body
    ------WebKitFormBoundaryECOAm72ObCFGjWIt
    Content-Disposition: form-data; name="image"; filename="image.jpg"
    Content-Type: image/jpeg
    <binary content of image.jpg>
    ------WebKitFormBoundaryECOAm72ObCFGjWIt
    Content-Disposition: form-data; name="customerId"
    123456
    ------WebKitFormBoundaryECOAm72ObCFGjWIt--
    

How to run in development

  1. In bash run cd react && npm run dev
    • If this is your first time running, in the react folder:
      • In bash run nvm use 22
      • Add & populate the .env.development and .env.productionfile
  2. In bash run cd csharp && dotnet run
    • If this is your first time running, in the csharp folder, in bash run dotnet add package Microsoft.AspNetCore.WebUtilities && dotnet add package SkiaSharp

How to run in production:

  1. In bash run cd react && npm run build so that a dist folder is created and populated
  2. Upload the the js and css files in react/dist/assets to the demo server
  3. Navigate to the aspx page that will hold the image upload component
  4. Wherever you'd love the image upload component to function add this: <div id="image-upload"></div>
  5. In the <head> add a <link> tag for the dist css file
    • Example: <link rel="stylesheet" href="image-upload.css">
  6. Just below the newly added <link> tag add a <script> tag for the dist js file
    • Example: <script src="image-upload.js" type="module"></script>
  7. Ensure the tag has type="module" so:
    • The browser continues parsing the HTML content while fetching and processing the module script
    • The script is executed only after the document's body has been fully parsed
    • Variables, functions, and classes declared in a module are scoped to that module and do not pollute the global namespace
    • Module scripts are automatically executed in strict mode, which enforces stricter parsing and error handling of JavaScript code
    • Supports ES6 module syntax like import & export

Packages

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published