Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Avoid uploading images to S3 in the listing process #63

Open
NwinNwin opened this issue Jan 12, 2025 · 0 comments
Open

feat: Avoid uploading images to S3 in the listing process #63

NwinNwin opened this issue Jan 12, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@NwinNwin
Copy link
Member

image

Description

  • Right now, when user upload a image in the listing process, image will automatically upload to S3 bucket.
  • This is inefficient, and open for spam attack.
  • Complete this task will help us save the cost of saving data significantly for ZotNFound!

Goal

  • Only upload the image to S3 once the user done placing the pin on the map (or finish the listing process)

To do

  • Remove the functionality in the step 4 to upload image directly to S3.
  • Instead, save the image in memory using something like FileReader to generate data URL
    • Doing this, we will avoid uploading image to server

Something I cooked up in GPT, idk if this will work lol:

import React, { useState } from "react";

const ImageUploadPreview = () => {
  const [imagePreview, setImagePreview] = useState(null);

  const handleImageUpload = (event) => {
    const file = event.target.files[0]; // Get the uploaded file
    if (file) {
      const reader = new FileReader();

      // Read the file and set the image preview once loaded
      reader.onload = () => {
        setImagePreview(reader.result);
      };
      reader.readAsDataURL(file); // Read the file as a data URL
    }
  };

  return (
    <div>
      <h2>Upload and Preview Image</h2>
      <input type="file" accept="image/*" onChange={handleImageUpload} />
      {imagePreview && (
        <div>
          <h3>Image Preview:</h3>
          <img
            src={imagePreview}
            alt="Uploaded Preview"
            style={{ width: "300px", height: "auto", marginTop: "10px" }}
          />
        </div>
      )}
    </div>
  );
};

export default ImageUploadPreview;

@NwinNwin NwinNwin added the enhancement New feature or request label Jan 12, 2025
@NwinNwin NwinNwin changed the title feat: Avoid uploading images to S3 in the listing process feat: Avoid uploading images to S3 in the listing process + Compress images when uploading to S3 Jan 13, 2025
@NwinNwin NwinNwin changed the title feat: Avoid uploading images to S3 in the listing process + Compress images when uploading to S3 feat: Avoid uploading images to S3 in the listing process Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants