I am trying to create a image upload site, where users can upload an image to the site.
Which is the easiest possible way to do this without using any plugin. How do you get exif/meta information from the image?
Specify you form type to be file.
$this->Form->create('Model', array('type' => 'file'));
$this->Form->input('filefield', array('type' => 'file'));
in you before save see the output of fielfield, it will contain the $_FILE like information, having all tmp-name, original filename and error code.
you can urself move_uploaded_files() to your convenient location. Store the filename into your table.
But, for the implementation you will have to deal with various things like two filenames having same name, file size, extensions allowed, permissions. Delete files when records get deleted.
So, for learning purposes u can try this out but for production mode it'd be better if you stick to a plugin.
Related
I want the user to upload his picture when he registers his information.
The thing is when the user uploads his image.. should automatically create a folder with his ID to be like this wwwroot/images/UserID/fadi.jpg
Basically: you really shouldn't. The wwwroot is for static assets used by the application. You're using server-side, so in theory it might be possible but that's not what the folder is meant for. An alternative method like AWS would be preferred, but if you can't do that (either because of payment requirements or other complications) I would suggest saving the image to your database. One way to do this would be to base64 encode the image and save it that way. I'm not going to give an example of that here, there are plenty available elsewhere. One such example is this.
I have image upload in my system. I am struggling to understand what is the logic of serving images.
If I upload directly to wwwroot, the files will be accessible to everyone, which is not what I want.
I understand I could save the file contents in the database as base64 but those can be big files, and I would like them on the server in files.
I could convert them on the fly when requested. Most probably getting the path to file, then loading it in a memory stream and spitting out the base64. But seems overkill, and not an elegant solution. I use Automapper for most data and I have to write some crazy custom mappers, which I will If there is no other way.
I could create virtual path, which from what I understand maps physical path on server to a url which doesn't seem any different than option 1
I fancy there is a way to spit out a link/url that this user has access to (or at least logged users) that can be passed to the app so it can load it. Is this impossible or unreasonable? Or am I missing something?
What is the correct way of doing in general?
Also, what is a quick way to do it without spending days for setup?
To protect the specific static files, you can try the solutions explained in this official doc.
Solution A: Store static files you want to authorize outside of wwwroot, and call UseStaticFiles to specify a path and other StaticFileOptions after calling UseAuthorization, then set the fallback authorization policy.
Solution B: Store static files you want to authorize outside of wwwroot, and serve it via a controller action method to which authorization is applied and return a FileResult object.
I have a document library that has some fields as compulsory but when I upload them sensenet does not required the fill of that fields.
This is working only on the edit function
The problem with this feature is that on the built-in UI you cannot actually fill any fields when you upload a document. So if you had any compulsory fields (and we validated them) you would not be able to upload documents at all, the system would deny that.
Currently I do not know an out-of-the-box solution for this, you would have to create a custom upload UI (of course using the built-in simple upload functionality) that makes sure the user fills the compulsory fields before uploading the doc.
If you think this is something we should look into, please create an issue on github.
Using POI4Xpages which is great LINK
However, I was wondering, at present, when it creates my word document, it simply downloads, like a normal download from the internet, storing it the downloads folder in windows (using Chrome anyways)
Is there a way, using POI4XPages, to instead, dump the file to a specified network location, for example a shared drive?
After that, I would simply build a link to the file using the network location, and a filename variable for example to pick the correct file.
If thats not possible, is it possible to get a handle on the file before or after it is downloaded, and then save it to a field in the xpage?
In short, I want to avoid the user downloading the file, then having to attach it manually to the xpage.
Thanks
POI allows you to get a handle to the file using the variable "workbook". You are also able to provide the specific downloadFileName you wish to use. Using the postGenerationProcess property you should be able to make a call to a Java method that makes the connection to your network drive where you can use the "workbook" variable and downloadFileName value to save your document. If this doesn't work definitely post a question on their project site because the creator does reply.
How do I restrict any access to the :original styled files in S3 but keep access to the rest of the styles's folders in the bucket?
I saw implementations on how to limit all access and then check on attributes of a model. I just want to limit access to :original styles
I did notice this line in paperclip, I just don't know how to use (if possible)
You can limit the files by accessing the files through an action of a controller. This way you can control, which files a user can access and which not.
If you simply make a privat s3 bucket, this won't help you. As a user with a valid key can access any files in the bucket. If you have really file which needs to be protected, you have only view ways to do it (as I think):
Restrict access to the bucket and serve the files through an action of a controller (no real way to work around this)
Rename the specific files to be not easy to predict (e.g. 32 or more characters of numbers and letters). This is quit simple to achieve and you can still serve the files directly from s3
Save the files somewhere else (maybe in an other s3 bucket), so nobody can predict them
For renaming files you can use this stackoverflow question: Paperclip renaming files after they're saved
The answer I am looking for (I think, didn't test it yet) can be found here
http://rdoc.info/github/thoughtbot/paperclip/Paperclip/Storage/S3
s3_permissions: This is a String that should be one of the "canned" access policies that S3 provides (more information can be found here: docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAccessPolicy.html) The default for Paperclip is :public_read.
You can set permission on a per style bases by doing the following:
:s3_permissions => {
:original => :private
}
Or globaly:
:s3_permissions => :private