# I would like to save my crop image to my django database called model filed file, help appricated - It been 3 days still stuck in this

**URL:** <https://forum.djangoproject.com/t/i-would-like-to-save-my-crop-image-to-my-django-database-called-model-filed-file-help-appricated-it-been-3-days-still-stuck-in-this/18055>\
**Category:** Forms & APIs\
**Created:** [January 7, 2023, 2:29pm UTC](https://forum.djangoproject.com/t/i-would-like-to-save-my-crop-image-to-my-django-database-called-model-filed-file-help-appricated-it-been-3-days-still-stuck-in-this/18055 "2023-01-07T14:29:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahiamrit](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shahiamrit/32/11638_2.png) [@shahiamrit](https://forum.djangoproject.com/u/shahiamrit)\
**Post date:** [January 7, 2023, 2:29pm UTC](https://forum.djangoproject.com/t/i-would-like-to-save-my-crop-image-to-my-django-database-called-model-filed-file-help-appricated-it-been-3-days-still-stuck-in-this/18055/1 "2023-01-07T14:29:10Z")

</div>

I have the following models.py

```auto
class Imageo(models.Model):
    file = models.ImageField(upload_to='cropped_images')
    uploaded = models.DateTimeField(auto_now_add=True)

    def __str__ (self):
        return str(self.pk)

```

I would like to savemy file into my Imageo models but it is saving into my database some other folder, please look at the views.py file.

```auto
def con(request):
    if request.method == 'POST':
        form = ImageForm(request.POST, request.FILES)
        if form.is_valid():
            image = Image.open(form.cleaned_data['file'])
            image = image.resize((200, 200), PIL.Image.ANTIALIAS)
            image = image.convert('RGB')
            dt = image.save('resize.jpg')
            # i would like to save resize.jpg into my models name called file
            return HttpResponse('done')
    else:
        form = ImageForm()

    img = Imageo.objects.latest('id')
    return render(request, 'NEC/imgCon.html', {'form': form, 'img': img})

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 7, 2023, 3:02pm UTC](https://forum.djangoproject.com/t/i-would-like-to-save-my-crop-image-to-my-django-database-called-model-filed-file-help-appricated-it-been-3-days-still-stuck-in-this/18055/2 "2023-01-07T15:02:28Z")

</div>

I’m not sure I understand what you’re asking here.

Uploaded files don’t get saved into the database. FileFields don’t contain the data, they contain the reference to where the file is stored.

---

<div class="post-metadata">

**Author:** ![shahiamrit](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shahiamrit/32/11638_2.png) [@shahiamrit](https://forum.djangoproject.com/u/shahiamrit)\
**Post date:** [January 7, 2023, 3:09pm UTC](https://forum.djangoproject.com/t/i-would-like-to-save-my-crop-image-to-my-django-database-called-model-filed-file-help-appricated-it-been-3-days-still-stuck-in-this/18055/4 "2023-01-07T15:09:04Z")

</div>

now resize.jpg got save in folder, i need it to save into my models name file.  
please help me with crop size 200\*200 file save into file models, please –

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 7, 2023, 3:40pm UTC](https://forum.djangoproject.com/t/i-would-like-to-save-my-crop-image-to-my-django-database-called-model-filed-file-help-appricated-it-been-3-days-still-stuck-in-this/18055/5 "2023-01-07T15:40:51Z")

</div>

When you upload a file, the file name used to store the file in the file system is not necessarily the name of the file as it was originally uploaded - it doesn’t need to be the same, and quite frequently, shouldn’t be the same.

Also, I don’t see where the `.save` function for an `Image` in `Pillow` returns anything.  
Therefore, I would expect after this line:

> [@shahiamrit](#):
>
> `dt = image.save('resize.jpg')`

that `dt` would be `None`. (see [PIL.Image - Pillow (PIL Fork) 10.1.0 documentation](https://pillow.readthedocs.io/en/stable/_modules/PIL/Image.html#Image.save))

So, what I think you might need to do is define the file object before the save, use that file object in the save, and then update your `Imageo.file` object with the reference to the new file you just created. (I would also use one of the system functions to allocate a randomly-named file to prevent overwriting an existing file.)
