I've got 2 ways to upload an image. 1 is choosing an image from the user's files and the other is for uploading an image via URL. 

**models**

```
class Post(models.Model):
    ...
    image = models.FileField(null=True, blank=True)
    imageURL = models.URLField(null=True, blank=True)

    def download_file_from_url(self):
        print('DOWNLOAD') #prints "DOWNLOAD"
        # Stream the image from the url
        try:
            request = requests.get(self, stream=True)
        except requests.exceptions.RequestException as e:
            # TODO: log error here
            return None

        if request.status_code != requests.codes.ok:
            # TODO: log error here
            return None

        # Create a temporary file
        lf = tempfile.NamedTemporaryFile()

        # Read the streamed image in sections
        for block in request.iter_content(1024 * 8):

            # If no more file then stop
            if not block:
                break

            # Write image block to temporary file
            lf.write(block)
            return files.File(lf)

```

**html**

```
    <input id="id_image" type="file" name="image" /> <!--upload from file-->
    {{ form_post.imageURL|placeholder:"URL" }} <!--url upload-->

```

The image upload from files works fine, the user just clicks on the input and it chooses their file. However when the user decides to use the URL option instead..how do I get that URL string and make it the value for the `image` field?

views

```
    ...
    if form_post.is_valid():
        instance = form_post.save(commit=False)
            if instance.imageURL:
                instance.image = Post.download_file_from_url(instance.imageURL)
                instance.save()

```

urls.py

```
...
if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

```

settings.py

```
...
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

```