0

In my views.py file, there are some functions like follows:

def upload_file(request):
    """
    upload a file and store it into the database,
    and the file will be predicted in another view immediately.
    """

def predict(request):
    """
    make prediction of the file uploaded in the 'upload_file' function.
    """

How to access the file which uploaded in upload_file function in the predict function? Here is my thought: 1. read the last row in the database, but this sounds a little silly. 2. use a cache system and retrieve the file from cache?

Is there any useful solution for this problem? please give me any hints or other resources.

Thanks for anyone's help.

1
  • These are different views? So they get called independently of each other, right? In that case you need a reference (pk) to the image uploaded to be passed into the predict view (i.e. via the URL or the request parameters)
    – dirkgroten
    Oct 21, 2017 at 15:42

1 Answer 1

0

As it is described here, you can acces the storage url as Follows :

Class MyModel(models.Model):
       photo = models.ImageField()

   model = MyModel.objects.get(pk=1) #          for instance

  model.photo.url
  >>> 'https://media.example.com/mymodels/example_image.jpg'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.