Umbraco: Saving media, not added to cache? - umbraco

I have a script that imports some legacy media into Umbraco media library. File gets saved, and is vissible in the backend, and when I access the direct url mywebsite.com/media/[id]/myfile.pdf - the file is loaded correct.
But, if I use the media (file or image) on the site, an image for instance, the image does not get shown. If i then find the image in the backend media library, clicks save, and nothing more, it works for that image.
But as there is 1000+ media files, this is not really an option to do manually.
I tried rebuilding the examine indexes, all of them, deleting them, deleting umbraco.config, temp folders etc.
Tried a small script that loops through all media files and saves them again mediaService.Save(mediaItem), but nothing works.
What am I missing?

Related

Flutter cannot retrieve iPhone file (sometimes)

I have an app that lets the user pick local files and send them to the backend to add to their vault. To pick the file, I use FilePicker.platform.pickFiles. It seems to work fine, the file is picked and when it's an image we show a preview to the user (and it always works).
Once the user has picked all their files, we create a list of Future to try and send the files to the backend, then we await the list to resolve. If we deem a picture is too big, we reduce the size using FlutterImageCompress.compressAndGetFile.
This usually works, but on iPhone, there is a seemingly random behavior where the file isn't found and an error is thrown : Cannot retrieve length of file, path = '/private/var/mobile/Containers/Data/Application/3600F812-FD42-4441-A654-766991E45E04/tmp/com.feykro.myApp.int-Inbox/myFile.pdf' (OS Error: No such file or directory, errno = 2)
The file in the example works just fine in other instances, the problem seems random and not directly tied to the file I chose. The problem is not exclusive to pdf files either, as it also occurs on images even though they're picked correctly and displayed in the app.
Any idea what could be causing this ?
Thanks in advance !

Using Backload to upload image to project file but images do not appear until project is rebuilt

Using MVC 4 I downloaded Blackcity Backload from nuget, I am trying to save the uploaded images to a file that is within my project. Everything works great and it shows that the image uploaded, except for the fact that after you upload a new image, and refresh the page the image does not appear in the list of returned images even though it was saved. Also if you delete a file it comes off the list at first but again if you refresh the page it is back. If you rebuild the application then everything appears as it should and the images in the backload file list are all listed correctly and they match what is in the actual file.
I thought it may be a server cache issue but I did all i can to prevent the server from caching and still same problem.
I think it may have to do with the fact that Backloader is dynamically creating folders to put the images in and they are not included in the project even though they are in the file structure. So since they are not part of the project they are not being returned in the get request. Its not until you rebuild that they are recognized as part of the project.
Is there a way to dynamically include new files in the project without rebuilding?
Please help. This is killing me.
Ok this is solved. Had to remove filters.Add(new AuthorizeAttribute()) from my global filters and then add [Authorize] to each controller and it worked.

Restoring/creating missing media references in Umbraco Media section

I have an Umbraco (v6.1.6) website, hosted on Azure Hosted (Website & DB).
Recently the client reported, that some images have disappeared from the website!
Looking at the CMS back office, the content nodes are referencing media items, but 'some' of those items are no longer present in the media section! The media files are however present on the web server in the /media folder as expected!
Now, this should be running as a single instance site, but looks like the site was run in with multiple(3) instances for a while, such as when the missing images were loaded.
[All the unaffected media has lower id’s (<10000) while the missing items in the media section have higher ids (20000’s or 50000’s)]
The site is now back to running one instance.
Q. Is there a way I can re-generate the items in the Umbraco Media section, based on the media actually present in the /Media folder?
What you need to do depends a lot on the state of your site and what has been going on while it was running in 3 instances... and what you want the outcome to be!
Metadata for media in umbraco is stored in the database and the actual files are stored on disk. If your site has been running in 3 instances using the same database but different file locations on disk, you should actually be seeing that the media items exist in the database even though the files might be scattered in the 3 instances on the file system.
It however sounds like you're saying that the files all do exist on disk, but the media items not all exist in the database. Can you confirm this (as it sounds really strange unless you have been running 3 different databases also).
All in all, everything here sounds really strange since running 3 instances should also require you to have had this running and accessed by the editors uploading the files, using 3 different hostnames?
No matter what I don't think theres a simple solution to your problem. There's no way to have umbraco "reindex" the media folder based on the files there. What I have done for broken media libraries (usually self inflicted breakage, that is) is to load up all existing media items in memory and then loop through the file system to see what is missing from the library and recreate those media items and upload the files to them. Do remember to log which files you are recreating as media items so you can do a file system delete of the orphaned files after they have been processed.
If you can shed a bit more light on the issue, I will see if I can come up with a better solution for you.

Updating iOS application content which include images

I am working on a Vegetable gardening application. Apart from the vegetable name and description I also have vegetable image. Currently, I have all the images in the Supported Files folder in the Xcode project.
But later on I want to update the application dynamically without having the user download a new version. When the user updates the application or downloads new data from the server that data will include the images. Can I store those images in the supporting file folder or somewhere where they can be references by just the name.
RELATED QUESTION:
I will also allow the user to take pictures of their vegetables and then write notes about the vegetables like "just planted", "about to harvest" etc. What is the recommended approach for storing pictures/photos. I can always store them in the user's photo library and then store the reference in the local database and then fetch and display the picture using the reference. The problem with that approach might be that if the user accidentally deletes the picture from the library then it will no longer be displayed in my application.
The only way I see if to store the picture in the app local database as a BLOB.
No you can't put the downloaded images with the others inside the supporting file folder. Also I would suggest you put the images inside an Images or Resources folder instead... If you want to download any data after the app is compiled, then they will not be in the bundle. It is the bundle you are referring to when talking about the Supported Files folder in Xcode. This is read only for your application.
Just to be clear, once compiled, there are no folder structures for your application, these "folders" are just groups in the Xcode project to keep things tidy.
If you download say a zip file containing a set of images, it's up to you to write them to disk after you download them. You should put these images in either the tmp, the cache or the documents directory.
But then you'll have to build your path before loading the images. You won't be able to just provide the name of the file such as:
[UIImage imageNamed:#"something.jpg"];
Because this will look in your bundle. Instead you must do something like this to load your image from the Documents directory for example.
Your challenge is that you will end up in a state where you'll have some images in the Bundle (the ones from when you uploaded your app), and the newer ones in the documents directory. You must them check the bundle first and if there is no image there, check the documents directory.
For user generated data, I suggest also saving the images in the Documents directory, and maintaining an SQLite database of the users data, so you can map an image name to an entry in the database. You don't want to save the images as BLOB because this will inevitably slow down the performance of your queries and add extra unnecessary load on the CPU to convert to UIImage and back.
You don't want to save their images to the gallery for 2 reasons, first this means you'll be saving in 2 places because keeping a reference in your database to an external image is very fragile and you're just asking for trouble, and secondly, once the image isn't under your wing, you don't control it anymore, the user will delete it at some point, if they go back to your app they expect to see it there.

where is the best place to save images from users upload

I have a website that shows galleries. Users can upload their own content from the web (by entering a URL) or by uploading a picture from their computer.
I am storing the URL in the database which works fine for the first use case but I need to figure out where to store the actual images if a user does a upload from their computer.
Is there any recommendation here or best practice on where I should store these?
Should I save them in the appdata or content folders? Should they not be stored with the website at all because it's user content?
You should NOT store the user uploads anywhere they can be directly accessed by a known URL within your site structure. This is a security risk as users could upload .htm file and .js files. Even a file with the correct extension can contain malicious code that can be executed in the context of your site by an authenticated user allowing server-side or client-side attacks.
See for example http://www.acunetix.com/websitesecurity/upload-forms-threat.htm and What security issues appear when users can upload their own files? which mention some of the issues you need to be aware of before you allow users to upload files and then present them for download within your site.
Don't put the files within your normal web site directory structure
Don't use the original file name the user gave you. You can add a content disposition header with the original file name so they can download it again as the same file name but the path and file name on the server shouldn't be something the user can influence.
Don't trust image files - resize them and offer only the resized version for subsequent download
Don't trust mime types or file extensions, open the file and manipulate it to make sure it's what it claims to be.
Limit the upload size and time.
Depending on the resources you have to implement something like this, it is extremely beneficial to store all this stuff in Amazon S3.
Once you get the upload you simply push it over to Amazon and pop the URL in your database as you're doing with the other images. As mentioned above it would probably be wise to open up the image and resize it before sending it over. This both checks it is actually an image and makes sure you don't accidentally present a full camera resolution image to an end user.
Doing this now will make it much, much easier if you ever have to migrate/failover your site and don't want to sync gigabytes of image assets.
One way is to store the image in a database table with a varbinary field.
Another way would be to store the image in the App_Data folder, and create a subfolder for each user (~/App_Data/[userid]/myImage.png).
For both approaches you'd need to create a separate action method that makes it possible to access the images.
While uploading images you need to verify the content of the file before uploading it. The file extension method is not trustable.
Use magic number method to verify the file content which will be an easy way.
See the stackoverflow post and see the list of magic numbers
One way of saving the file is converting it to binary format and save in our database and next method is using App_Data folder.
The storage option is based on your requirement. See this post also
Set upload limit by setting maxRequestLength property to Web.Config like this, where the size of file is specified in KB
<httpRuntime maxRequestLength="51200" executionTimeout="3600" />
You can save your trusted data just in parallel of htdocs/www folder so that any user can not access that folder. Also you can add .htaccess authentication on your trusted data (for .htaccess you should kept your .htpasswd file in parallel of htdocs/www folder) if you are using apache.

Resources