How to save screenshot to CloudinaryField in django using chromedriver on Heroku?

When I do driver.save_screenshot, even if return returns true, the file is not there.

How do I save the screen_shot to the database?

someone teach me...

#models.py

class UploadedImage(models.Model):
image = CloudinaryField('image', blank=True, null=True,
                        folder="media")
author = models.ForeignKey(
    User, on_delete=models.CASCADE, null=True, blank=True
)
created_at = models.DateTimeField(auto_now_add=True)
token = models.CharField(max_length=256, null=True, blank=True)

#views.py





options = Options()
options.add_argument('--disable-gpu')
options.add_argument('--disable-extensions')
options.add_argument('--proxy-server="direct://"')
options.add_argument('--proxy-bypass-list=*')
options.add_argument('--start-maximized')
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(executable_path=driver_path, chrome_options=options)
driver.get('https://weather.yahoo.co.jp/weather/')
driver.set_window_size(1250, 1036)
driver.save_screenshot('/app/a.png')
UploadedImage.objects.create(image='/app/a.png')




return HttpResponse("Success", request)

heroku ps:exec

heroku run bashでは新しいdynoが作成されるため

そのdyno内には保存したファイルはない。

上記の ps:execで一時ファイルが保存されているメインdynoへとアクセスできる。

また、コマンドでファイルをローカルに持ってくる場合は

heroku ps:copy filename

When you move a saved image to a local location, the

heroku run bash creates a new dyno, so

There are no saved files in that dyno.

The above ps:exec will take you to the main dyno where the temporary files are stored.

Also, if you want to bring the file locally with the command

Back to Top