0

My problem is that when I upload the image to firestore storage, it is getting uploaded, but when I open the image I get a 404 error: "The requested URL was not found on the server."

I included the code below.

I have tried upload_from_file(), upload_from_string(), and upload_from_filename(), but nothing seems to work.

views.py

import PIL
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from django.conf import settings

@login_required
def create_event(request):
    form = EventForm()
    if request.method == "POST":
        form = EventForm(request.POST, request.FILES)
        if form.is_valid():
            print("my form dynamic details  ", request.POST)
            print("my files ", request.FILES['cover_image'])
            path = default_storage.save(
                'tmp/'+request.FILES['cover_image'].name,
                ContentFile(request.FILES['cover_image'].read())
            )

            of = open('media/tmp/'+request.FILES['cover_image'].name, 'rb')
            print("my of ", of)

            # I have tried all the methods below but doesn't work at all.
            blob = bucket.blob(request.FILES['cover_image'].name)
            blob.upload_from_file(of, content_type="image/jpeg")
            # blob.upload_from_string(request.FILES['cover_image'].name, content_type="image/jpeg")
            # blob.upload_from_filename(filename='media/tmp/'+request.FILES['cover_image'].name)
            print(
                "File {} uploaded to {}.".format(
                    request.FILES['cover_image'].name, "jigarfile.jpg"
                )
            )

            return redirect('create_event')
        else:
            print("my erros ", form.errors)
    return render(request, 'user/events.html')


Below I attach the image

enter image description here

Jigar Panchal
  • 93
  • 3
  • 12

0 Answers0