Upload webscrapped images from folder to database Django - sql

I'm webscrapping data about ski resorts from a site, also getting some pictures. I am saving those pictures in a folder and after that i'm getting them in SQLite database through an imageField.
The bad part is that they don't work
directory = r'C:\Users\tiberiu.ghimbas\Documents\Resorts img5'
image_list = [cv2.imread(file) for file in
glob.glob(r'C:/Users/tiberiu.ghimbas/Documents/Resorts img5/*.png')]
This list is then looped and insertet item by item.
I'm doing all the correct settings for handling images and media files.
I know that by going the classic way of uploading images through a form will get you in the database the path to the image from de media/"upload_to = 'filename'" folder but going by my way i'm getting only them image name.
How can i solve that ?

Related

What is the best place to store module uploaded images

I am creating a module that allows to create some objects and upload images for them.
For the moment, I am uploading images in the module folder itself. But I think it is better to store them in PS img folder like for product and category images. One of the reasons is to avoid their deletion when module is deleted mistakenly from backoffice.
Is there any other reason to store/ not store images in img folder? What is the best place to store a huge number of uploaded images?
Your ideas are much appreciated. Thanks in advance.
Yes, it's better to save your images in the img folder. The most important reason for doing this: this route will never be blocked by robots.txt.
In my modules, (in order to be more orderly,) I create a folder called "module" and then inside this folder, I create another folder called the my-module-name.
img/modules/my-custom-module/test.jpg

Moving uploaded files in Socialengine

I tried moving uploaded file through browse action in socialengine from /public/user/ to /Files/SE/ by using
1.
$fileobj = new Zend_Cloud_StorageService_Adapter_FileSystem();
$fileobj->moveItem($sourcePath, $destinationpath);
move_uploaded_file($sourcePath, $destinationpath);
Both of these couldn't move the file. I have checked the paths too they are perfect and works with other frameworks
You should use API of Storage module which will allow you to create temporary files (when you need to resize images or convert videos) and then place them into public storage. This files will be tracked in engine4_storage_files table.
I got it worked by using createSystemFile() function under storage > Model > DbTable > Files.php
I created a function similar to this and gave parent_type as the folder which I wanted to move in the files.

Storing Uploaded file in database

I place a simple fileupload control in my webform application. firstly user have to login and his login username is stored in a session. then user have option to upload his pic. I place an image control.If pic is available it is shown in Image control. My fileupload code is
string sp = fileuploadpanno.FileName;
string fn = Server.MapPath("~/panno/" + sp);
fileuploadpanno.PostedFile.SaveAs(fn);
My question is how to save this file into database. I am using mysql database.
You could potentially store the image in the database directly by first converting it to a BLOB.
A more widely used practice is to store the image in a directory/location such as App_Data or Temp and then store the image name in your mysql database. Then when you want to reference the image in your web application you can just use a normal image tag with the source being the location of the image concatenated to the image name you retreive from your database.
So for example if I have a directory /App_Data/Images/
And I store an image name in my database called my_image.jpg
After moving the image above to the directory above (save it in this location) I can then reference it by appending the image name to the location /App_Data/Images/my_image.jpg

iOS file system: adding/removing/sorting files

I have a directory with images like this:
0000.png
0001.png
0002.png
0003.png
etc...
To add an image, I query the count of the directory and name the new file with the count. I need to maintain such an order because these images are eventually displayed in a grid view. This is the easy part. What is bugging me is manipulating the directory later.
The user can delete and reorder these as they wish. So how should I handle reordering of the actual directory?
I have tried, naively, copying the images into an NSMutableArray, loading those into the gridView, letting the user manipulate, then upon finish I wipe the directory and rewrite the images. That's fine for a few images, but there can be many and it slowly builds up.
I like the idea of copying the images locally, manipulating and then fixing the directory. But I think there has got to be a better way to manage the directory instead of wiping and rewriting, would it be faster to write some kind of file-swapping method?
Instead of writing the images to the file system in an ordered format, you could have a meta data file images.plist
And maintain an NSMutableArray of NSDictionaries
Each dictionary will contain the data for the imageFile Path and the image index
Then when you would save the changes of the user you will only rewrite this plist file, instead of saving all the images again

Detecting corrupted jpg files before or during upload

I have an ASP application that uses ASPImage.Image to resize the uploaded image and then save the file to the server and save it in the database. However, it appears that if a user uploads a corrupted file the resulting image is blank white image.
I need a way to check if the file is corrupted before the image is passed to ASPImage.Image, that will then inform the user that the file is corrupted.
Can this be done with javascript, vbscript or ASPImage.Image itself?
Any assistance would be greatly appreciated.
Best Regards,
Paul Jacobs
There is no way to detect a corrupt image in either javascript or vbscript - you will need to try using ASPImage.Image directly.
It has an Error property, this will probably have an error detailing that a corrupt file has been loaded - did you try that? That is, if it is populated, chances are that the file was corrupt.
Additionally, the LoadImage method returns a boolean - I assume it will return false if the image couldn't be loaded due to corruption.
You can use the code here: http://forums.aspfree.com/code-bank-54/pure-asp-upload-script-with-additional-features-94647.html
Then check the image Width and Height - if 0 it means the uploaded file was not a valid image.
This is pure classic ASP code without third party components.