Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploader Class #113

Closed
8 tasks
lonnieezell opened this issue Jun 15, 2016 · 12 comments
Closed
8 tasks

Uploader Class #113

lonnieezell opened this issue Jun 15, 2016 · 12 comments
Labels
in progress new feature PRs for new features
Milestone

Comments

@lonnieezell
Copy link
Member

lonnieezell commented Jun 15, 2016

This is a new class that takes the place of CI3's File_Uploader class.

  • Must accept the current IncomingRequest object to get the files from in the constructor
  • Must use the FileCollection and UploadedFile class features
  • Must be able to work with multiple files at once
  • Should make it easy to create multiple thumbnails of each image with size appended to name
  • Should provide standard size limits and verification (both file size and image dimensions, if image)
  • Should provide option to reset the orientation so it displays correctly.

Most of the image features should be handled through a new Image class.

Development Checklist:

  • Component(s)
  • ... with PHPdocs
  • Unit testing
  • ... with >80% coverage
  • User guide updated
  • Classmap integration?
  • Securely signed commits
  • Conforms to style guide
@lonnieezell lonnieezell added the new feature PRs for new features label Jun 15, 2016
@lonnieezell lonnieezell added this to the Pre-Alpha 2 milestone Jun 15, 2016
@orionstar
Copy link

I think the thumbnail creation should be decoupled from the Uploader class. Maybe the uploader should implement some kind of pubsub pattern or should use the events what you mentioned in the ticket about the queue interface.

@lonnieezell
Copy link
Member Author

You're absolutely correct. My last line there implied this, but wasn't very specific:

Most of the image features should be handled through a new Image class.

An issue exists for this one already, actually: #114

Using hooks/events (which is a pub/sub pattern basically) is an interesting idea, and I can see it being potentially very handy. Definitely something to consider more as we get closer to start working on it.

Thanks!

@davidgv88
Copy link
Contributor

+1 "Must be able to work with multiple files at once"

@lonnieezell lonnieezell added the help wanted More help is needed for the proper resolution of an issue or pull request label Jul 11, 2016
@davidgv88
Copy link
Contributor

@lonnieezell I'm trying to make the Uploader Class

https://github.com/davidgv88/CodeIgniter4/blob/upload_class/system/Uploader/Uploader.php

$options = array(
            'allowed_types' => array('jpg','png','gif'),
            'max_size' => 100
);
$uploader = new \CodeIgniter\Uploader\Uploader(\Config\Services::request(), $options);


$do_upload = $uploader->doUpload('file');

$uploadData = $uploader->uploadData();

@lonnieezell
Copy link
Member Author

Looks like a good start. A couple of comments and/or thoughts:

  1. You'll need to make sure that Ll comments are in English, please.
  2. Error strings will need to be localized
  3. Does it make sense to just return the file objects, instead of keeping a separate record of success and path in $dataUploads?

@lonnieezell lonnieezell added in progress and removed help wanted More help is needed for the proper resolution of an issue or pull request labels Sep 15, 2016
@lonnieezell
Copy link
Member Author

The more I think about this the more I'm thinking this library isn't needed anymore. The FileCollection class that can be retrieved from the current Request object fulfills all of the standard requirements of being able to upload the files, I believe. Any image-related features would be part of the image library, anyway.

Does this make sense to everyone?

@lonnieezell
Copy link
Member Author

Actually realized, also, that I started to add some file-related validation rules last night, and that pretty much fills out the basics of the uploader class, when combined with the existing UpoadedFile class.

I really think the upload class is unnecessary now, but I'll wait a few days to get other's comments before closing this.

@orionstar
Copy link

An upload class can provide some convience feature such as file type restriction, auto encrypt filenames, transform filename to lowercase etc. I use these in my own applications. I don't think these belongs to the HTTP "package".

@lonnieezell
Copy link
Member Author

To be fair, though, uploaded files are part of the HTTP request so it makes sense to deal with them there, like any other form input.

Currently, you can grab all of the uploaded files from the request, and they are represented by an UploadedFile class that uses best practice and most secure methods I could find for correctly determining type, etc. It also has a move() method to move the file from it's temp location to the location of your choice. It also takes care of generating a secure random name if you want.

The Validation library now has elements to validate if a file is an image, restrict to certain mime types or extensions, set a maximum file size or, if an image, maximum dimensions. These all make sense as you are validating an HTTP input, just like you would validate everything else on the form.

So, the only things left from the current Upload class are some of the file naming/move options (like the lowercase option, or removing spaces, or overwriting/appending version numbers to file name. Setting things to lowercase or removing spaces can be done manually when you specify the name, though we could provide options in the File class, though I think that's perhaps stretching it, but would be handy. The overwrite options would make sense to go into the UploadedFile class since the move method is there already.

At that point, I believe all of the current Uploader library functions are taken care of in a way that's actually a little more true to the HTTP process than we have been.

At least, it seems to all make sense to me....

@orionstar
Copy link

I was thinkg about it with your message in mind, and you're right! The approach is new but the result is the same as used to...

@mwhitneysdsu
Copy link
Contributor

So, the only things left from the current Upload class are some of the file naming/move options (like the lowercase option, or removing spaces, or overwriting/appending version numbers to file name. Setting things to lowercase or removing spaces can be done manually when you specify the name, though we could provide options in the File class, though I think that's perhaps stretching it, but would be handy. The overwrite options would make sense to go into the UploadedFile class since the move method is there already.

File naming rules and whether to allow overwrite (or what to do if naming conflicts arise) sound like either validation or lower-level business rules. While CI traditionally could do all of this stuff in the form_validation library, I don't know whether that's where you actually want it to reside in this case.

After looking up a couple of file move commands/functions/methods, it looks like it's fairly common to pass the source filename (obviously not needed in cases like the UploadedFile class, where this is already known), the destination path/filename, and, in complex methods, an options field, which usually includes a flag to allow overwrite. PHP's rename() accepts a context, which can include options like overwrite when it makes sense for the type of stream in use.

@lonnieezell
Copy link
Member Author

Sorry if that was confusing. The naming rules wouldn't be part of validation. They'd be part of the UploadedFile class, which already has a move() method. Sending the overwrite/append a number/etc rules as part of an options array would work great for that, I think, and definitely should be looked into a little more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in progress new feature PRs for new features
Projects
None yet
Development

No branches or pull requests

4 participants