Giter Club home page Giter Club logo

stapler's People

Contributors

aarongustafson avatar anhskohbo avatar benallfree avatar hafizbadrie avatar jasonmccreary avatar jorenvanhee avatar kara-todd avatar kdocki avatar kevincassier avatar lostincode avatar marsderp avatar mohangk avatar mozmorris avatar mvdstam avatar nyholm avatar rtablada avatar sillylogger avatar tabennett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stapler's Issues

page hangs when attempting to store file to s3

When attempting to store a file to s3 the upload status reaches 100% and then the status bar says waiting on drccweb.org. Nothing happens after that and no files are stored on s3

I'd be glad to send you an email to the page that is showing this problem if you can let me know where to send it.

Thanks Travis.

php artisan stapler:fasten has Windows style EOF

Getting crlf when I git commit a migration file created by php artisan stapler:fasten. This file was created back when I was on a windows box and doing development so I am going to run a dos2unix on it and hopefully that fixes it.

[Proposal] Configure the field in database

Hi I was wondering if it was possible to customize the fields used in the database. For instance it would be interesting to save only filename in database to avoid overloading the system too much (I like to keep my database schema as light as possible)

S3 storage causing multiple guzzle http requsts.

Using S3 storage is causing multiple http requests to occur when accessing image urls across a collection of models. We need to cache the base url for a given bucket once and then use that url to build image paths for subsequent requests.

No error, good data in DB but file is not present on filesystem.

Hi,

I use stapler since yesterday, I read the installation manual and everything worked like a charm. Except that today, it's not working, no idea why. I removed almost all the code I added since yesterday but no change.

There is no error, nothing in logs, everything seems to work well but the file is not present in my system folder. Everything is OK in the database, config is default (I tried to generate the config and change defaults folder but without any luck.)

No permission complain, tried with 777, no changes.

I really don't understand what's wrong...

Any idea ?

Edit :

Already tried :

  • clean storage/cache, storage/session
  • check php.ini settings (upload_tmp_dir, size limit, etc.)
  • restart apache
  • check phpinfo for GD
  • chmod 777 public/system
  • chmod 777 app/storage
  • chown almost everything to _www:staff in my laravel project (running osx maverick)
  • check all storage/logs/ files
  • check apache logs file
  • check system logs file

Note : I use andrew13/Laravel-4-Bootstrap-Starter-Site, I'm new to Laravel since yesterday, but not new to frameworks (silex, symfony, ror).

Edit2 : code

City Model

class City extends Eloquent {

    use Codesleeve\Stapler\Stapler;

    public function __construct(array $attributes = array()) {
        $this->hasAttachedFile('cover', [
            'styles' => [
                'large' => '1170x160',
                'medium' => '970x133',
                'small' => '750x103'
            ]
        ]);
        parent::__construct($attributes);
    }

Cities Controller

public function postCreate()
    {

        // Declare the rules for the form validation
        $rules = array(
            'title'   => 'required|min:3',
        );

        // Validate the inputs
        $validator = Validator::make(Input::all(), $rules);

        // Check if the form validates with success
        if ($validator->passes())
        {
            // Update the city data
            $this->city->title            = Input::get('title');
            $this->city->slug             = Str::slug(Input::get('title'));
            $this->city->meta_title       = Input::get('meta-title');
            $this->city->meta_description = Input::get('meta-description');
            $this->city->meta_keywords    = Input::get('meta-keywords');
            $this->city->cover            = Input::file('cover');
            $this->city->opened           = Input::get('opened');
            $this->city->activated        = Input::get('activated');

            // Was the city created?
            if($this->city->save())
            {
                // Redirect to the new city page
                return Redirect::to('admin/cities')->with('success', Lang::get('admin/cities/messages.create.success'));
            }

            // Redirect to the city create page
            return Redirect::to('admin/cities/create')->with('error', Lang::get('admin/cities/messages.create.error'));
        }

        // Form validation failed
        return Redirect::to('admin/cities/create')->withInput()->withErrors($validator);
    }

View

    <form class="form-horizontal" method="post" action="@if (isset($city)){{ URL::to('admin/cities/' . $city->id . '/edit') }}@endif" autocomplete="off" enctype="multipart/form-data">

<!-- City Cover -->
                <div class="form-group {{{ $errors->has('cover') ? 'error' : '' }}}">
                    <div class="col-md-12">
                        <label class="control-label" for="cover">{{{ Lang::get('admin/cities/table.cover') }}}</label>
                        <?= Form::file('cover') ?>
                        {{{ $errors->first('cover', '<span class="help-inline">:message</span>') }}}
                    </div>
                </div>
                <!-- ./ city cover -->

Edit : last one...

New test, adding avatar to my user table... everything work like a charm. City still doesn't work, I don't know why, is there any config stored in some place for each model ?

Tall images being automatically rotated.

I am using the latest beta version of Stapler with the stapler:refresh command and have noticed that when I upload a tall image, it gets processed and the resulting uploaded image is rotated to be a landscape image. Can anyone else verify that this is happening? I am using GD as my image processor and my model has the following code:

public function __construct($attributes = array()){
    $this->hasAttachedFile('image',[
        'styles'=>[
            'full' => '1000x1000',
            'medium' => '500x1000',
            'thumb' => '150x150#',
            'tinythumb' => '75x75#'
        ]
    ]);
    parent::__construct($attributes);
}

Human Readable size

I'm new to Laravel and it's design so i'm like 90% positive this isn't the correct place for this code. Either way, having an option to return a Human Readable attachment size was something I needed in a project I've been working on.

I was thinking something like this in Attachment.php would be helpful, but looking at the rest of the file i'm guess it's not where where something like this should live.

Thoughts?

    /**
     * Returns a human readable size of the attachment. 
     * 
     *  @return string
     */
    public function humanSize() 
    {
        $decimals = 2;
        $bytes = $this->instance->getAttribute("{$this->name}_file_size");

        $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
        $factor = floor((strlen($bytes) - 1) / 3);
        return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
    }

Validation

Hey, I was wondering where exactly I should validate the image to for example make sure its even an image (otherwise mimetype check crashes). Is there anyway for example to validate hasAttachedFile('photo') from the model itself?

Remote image download throws exception

If the url for a remote image does not contain a "proper" extension (e.g. seo formatted urls or urls with query strings), the remote file download functionality throws an exception:

Imagine \ Exception \ InvalidArgumentException
Saving image in "0?lm=20130905t051456" format is not supported,
please use one of the following extension: "gif", "jpeg", "png", "wbmp", "xbm"

One workaround to get the file downloaded is to add a dummy query string to the end of the file to download, such as "&x=file.jpeg". This lets the download work correctly, but then the query string and everything is part of the file name of the file on the server (file on server is "0?lm=20130905t051456&x=x.jpeg"). Additionally, the file is not accessible from the browser, as far as I have been able to tell.

Two options I see:

  • Have the IOWrapper->createFromUrl() method try to come up with a sensible filename and extension based on the curlinfo data.
  • Allow some way to set the desired file name for remotely downloaded files. This may be part of implementing proposal #36 (though you'd need to be able to set the file name before downloading), or could be completely separate.

Use single table and set as relationship

Hi

I think it would be a great addition to use Stapler as a single table, e.g managed_files.
The table would include a morphTo relationship to have multiple model types create a relation to it. Other models would then need morphMany or morphOne.

The hereto described structure can be quite easily implemented, however pushing a file from a model to its managed_files relationship seems to be impossible at the moment..

A code example:

Let's say the managed_files table looks like this:

$table->increments('id');
$table->morphs('model');
$table->string('file_file_name')->nullable();
$table->integer('file_file_size')->nullable();
$table->string('file_content_type')->nullable();
$table->timestamp('file_updated_at')->nullable();

The ManagedFile model:

class ManagedFile extends Eloquent {
    public function model() {
        $this->morphTo();
    }
}

Another model, let's say User:

class User extends Eloquent {
    public function __construct() {
        $this->hasAttachedFile('avatar[file]');
    }
    public function avatar() {
        $this->morphOne('ManagedFile', 'model');
    }
}

No matter how I try to feed hasAttachedFile with the uploaded file data, it still tries to find the corresponding columns in the User table instead of in the related model table.

I don't know a lot about the internals of Stapler, but a quick suggestion may be to have hasAttachedFile support a parameter for setting a custom defined table and/or base column name.

This way the file can be called as $user->avatar->file->url() or if a custom getAttribute method or presenter has been set still as $user->avatar->url(). Moreover as the hasAttachedFile is still set in the related model (User), model specific configurations can still be set.


Note: the idea about using a single table originates from Drupal.

Updating Form

while updating how can i upload new image.

while updating form when i upload new image causing errors
code:
$input = array_except(Input::all(), '_method');
$validation = Validator::make($input, Owner::$rules);

    if ($validation->passes())
    {
        $owner = $this->owner->find($id);
        $owner->update($input);

        return Redirect::route('owners.show', $id);
    }

[Improvement] Make Stapler work with laravelbook/ardent

Ardent extends Eloquent with some nice features, mainly in respect to validations.
However stapler fails to attach any files to an Ardent model and fails silently.

As Ardent has all the features of Eloquent I thought it might be easy to add support but after looking at the source I'm not entirely sure its possible because Ardent extends

 Illuminate\Database\Eloquent\Model

and not the Eloquent class itself which also extends the Eloquent\Model class

Do not keep original file

Hi,

How to tell Stapler to not keep the original file ? (I set 2 styles : full (1024) and thumb (200x100#), I don't want to preserve the original file because it's using extra space on my drive and I will have thousands of images.

Thanks,
Pierre

How do I get the S3 file url?

My use case has a single file attachment directly on a comment record. I added a field named 'attachment' to the comment record. I'm successfully uploading file to S3 but can't figure out how to retrieve them.

I get the Comment object then try

$comment->url()

or

$comment->attachment->url()

Those both error with Undefined property

In my comment model I have

$this->hasAttachedFile('attachment',[
    'storage' => 's3',
    'bucket' => 'myBucket',
    'ACL' => 'public-read',
    'path' => ':attachment/:id/:filename',
]);

Best way to do private files (non-public)

Hello,

Whats the best way to do some of the files as "non-public". I would like to have some private files stored in app/storage/ rather than public/system. These private files would obviously need a route to check for auth and serve up the file (but thats unrealted to stapler).

Options I've thought of:

  • set public_path config to be realPath(base_path()) and then set 'url' => '/public/system/:attachment/:id_partition/:style/:filename', on every model I use for public and set set 'url' => '/app/storage/private/:attachment/:id_partition/:style/:filename', on every private file's model.
    • sounds like a pain if only one model uses private files
  • set the url to be 'url' => '../app/storage/private/:attachment/:id_partition/:style/:filename', (notice the "..") on only my private models (I dont know if the "../" will work).

Is there a better way to do this?

problem with Observer on model

Hi,
There was a problem when using Observer on Model. I have "Company" model and Observer set on it according to Laravel documentation:

public static function boot()
    {
        parent::boot();

        self::observe(new CompanyObserver);
    }

and Observer class has one job: to clear "Location" relation after object deletion (it shouldn't have anythign to do with "Company" store/update, but it messes it up, see below):

class CompanyObserver {

    public function deleted($model)
    {
        $model->location->delete();  // <-- if I comment this line out everything starts to work
    }
}

now when I add your file attachement code:

use \Codesleeve\Stapler\Stapler;
    public function __construct(array $attributes = array())
    {
        $this->hasAttachedFile('logo');

        parent::__construct($attributes);
    }

then what happens is that after saving/updating "Company" model, fields in database are successfully populated with image details, but file is never written either to filesystem nor uploaded to S3. And no error is thrown.

Please advise what can I do to be able to still use observer class and your file upload facility.

Thank you.

Error in StaplerServiceProvider.php

Getting this error when running composer update command. ??

{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"syntax error, unexpected '['","file":"/home/damascu1/drccweb/vendor/codesleeve/stapler/src/Codesleeve/Stapler/StaplerServiceProvider.php","line":118}}{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"syntax error, unexpected '['","file":"/home/damascu1/drccweb/vendor/codesleeve/stapler/src/Codesleeve/Stapler/StaplerServiceProvider.php","line":118}}Script php artisan clear-compiled handling the post-update-cmd event returned with an error

Updating an image doesn't get written to the table

I'm having a weird problem where, initially, if I wanted to create a 'user', with an 'avatar', I would have to create the user through the adding of the avatar, then update the rest of the fields accordingly:

$user = User::create(['logo' => Input::file('logo')]);  
$user->save();

$user_id = $user->id;
$user = User::find($user_id);

$user->user_id = $user_id;
$user->save();

Surely one should be able to add a logo/image to any table even if it's already in existence?

Now upon trying to 'update' that user's logo, it doesn't even seem to get it from the form that's been filled out:

View:

<div class="form-group">
    {{ Form::label('logo', 'Company Logo') }}
    {{ Form::file('logo') }}
</div>

Controller:

$logo = Input::file('logo');
    if($logo !== null)
        {
            $user->logo->clear();
            $user->logo->$logo;
        }
    $user->save();

Model:

class User extends Eloquent {

    use Codesleeve\Stapler\Stapler;

    protected $guarded = array();

    public function __construct(array $attributes = array()) {
        $this->hasAttachedFile('logo', [
            'styles' => [
            'medium' => '300x300',
            'thumb' => '100x100'
            ]
            ]);

        parent::__construct($attributes);
    }
}

It doesn't even seem to pick the logo up? Am I missing something? I can't find any documentation on how to replace an image correctly, so I apologise in advance.

[Help!] "Permission denied" despite chmodded 0777 upload directory

Im currently trying to incorporate a small gallery system into my application. Users can upload pictures to galleries and the pictures are getting resized to 3 different sizes for the thumbnail view, medium view and full view.

<?php

class Picture extends Eloquent {
    use \Codesleeve\Stapler\Stapler;

    protected $table = "user_pictures";


    public function __construct(array $attributes = array())
    {
        $this->hasAttachedFile('picture', [
            'styles' => [
                'full' => '512x512',
                'medium' => '256x256#',
                'thumb' => '96x96#',
            ],
            'url' => '/uploads/images/:attachment/:style/:id_partition/:filename',
            'keep_old_files' => true
        ]);

        parent::__construct($attributes);
    }

    public function user()
    {
        return $this->belongsTo('User');
    }

}

My upload part of my function looks like this:

$gallery = Gallery::find($id); // we get this through POST 
$file = Input::file('file');

$picture = new Picture;
$picture->picture = $file;

if ($gallery->pictures()->save($picture))
{
    return Response::json('success', 200);

} else {
    return Response::json('error', 400);
}

The image gets added to the database correctly and the uploads/ folder is 0777-chmodded as well. So no big deal there.
However, the real problem I'm having is completely unclear to me:

{
  "error":
  {
    "type": "Imagine\\Exception\\RuntimeException",
    "message": "imagejpeg(.IMG_0014.JPG): failed to open stream: Permission denied",
    "file": "\/Users\/spaceemotion\/dev\/laravel\/vendor\/imagine\/imagine\/lib\/Imagine\/Gd\/Image.php",
    "line": 691
  }
}

The php-tmp folder is writable as well, I tested that through other applications.

Why do I still get a permission denied? What am I doing wrong?

[Proposal] rename attachments

It would be nice to be able to rename an attachment's name. If the attachment has already been saved it will rename the <attachment>_file_name in the database and also rename the existing file on the filesystem (or S3 or whatever driver).

If the attachment has yet to be saved it would just simply update <attachment>_file_name on that instance.

There are some examples out there how paperclip handles this... but I think if you had this

$model->attachment->rename('some file.jpg');

it would work nicely and is simple enough to use.

[Bug] why remove all the directory

In the filestorage there is something odd

https://github.com/CodeSleeve/stapler/blob/development/src/Codesleeve/Stapler/Storage/Filesystem.php#L58

when we want to delete a file the code delete the parent directory. but if we have multiple files in the same directory this line will automatically delete it.

It would be better to just delete the file and then check recursively parents directory (delete them if they are empty). before doing any commit I was wondering if this behaviour is "normal".

store more than one file with a single record

What is the best method to store multiple files with a single record. I have a need to store an image, an mp3, and an mp4 file and associate them with a single record. I don't really need a one-many relationship since there will never be more than one of each type of file being stored. My implementation works great if I just select one file with my form, however, if I select more than one the save function errors out with this error:

Illuminate \ Database \ QueryException
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null (SQL: insert into sermons (title, subtitle, speaker, desc, msgdate, updated_at, created_at) values (, , , , , 2014-01-14 23:46:08, 2014-01-14 23:46:08))

It's like it looses the reference to the instance of the newly created record. Here is the code from the function that handles adding a new record:

public function handleCreate()
{
    //handle create form submission
    $sermon = new Sermon;
    $sermon->title = Input::get('title');
    $sermon->subtitle = Input::get('subtitle');
    $sermon->speaker = Input::get('speaker');
    $sermon->desc = Input::get('desc');
    $sermon->msgdate = Input::get('msgdate');
    $sermon->imgfile = Input::file('imgfile');
    $sermon->mp3file = Input::file('mp3file');
    $sermon->mp4file = Input::file('mp4file');  
    $sermon->save();

    return Redirect::action('SermonsController@index');
}

I've looked for documentation on this but just cannot seem to find any. Any help would be greatly appreciated.

Uploaded file is named missing.png

When I upload an image (jpg) the image is stored as missing.png instead of being placed in the appropriate folder specified by the config file.

The upload images should be placed in /public/assets/media

Before upload:
/public/assets/media -> empty

After upload:
/public/assets/media/Marquee/images/full/missing.png
/public/assets/media/Marquee/images/medium/missing.png
/public/assets/media/Marquee/images/original/missing.png
/public/assets/media/Marquee/images/thumb/missing.png

Expected result:
/public/assets/media/Marquee/images/full -> empty
/public/assets/media/Marquee/images/medium -> empty
/public/assets/media/Marquee/images/original -> empty
/public/assets/media/Marquee/images/thumb -> empty
/public/assets/media/Marquee/images/000/full/myimage.jpg
/public/assets/media/Marquee/images/000/medium/myimage.jpg
/public/assets/media/Marquee/images/000/original/myimage.jpg
/public/assets/media/Marquee/images/000/thumb/myimage.jpg

=== Contents of /app/config/packages/codesleeve/stapler/filesystem.php ===

'/assets/media/:class/:attachment/:id_partition/:style/:filename', 'path' => ':laravel_root/public:url', 'override_file_permissions' => null, ];

Example of how to call the destroy method

Travis,

Can you provide an example of where to place the destroy method and how to call it from an edit form?

My form has 4 file types and I'd like to place a button next to each file that would just remove that file. But, I'm not sure how to make this call from my edit form and do I need to redirect back to my edit form ->withInput() after the file is destroyed?

Resizer leaves empty temp files

The resizer->resize() method starts with the following line:

$filePath = tempnam(sys_get_temp_dir(), 'STP') . '.' . $file->getFilename();

This uses the tempnam function, which actually creates an empty file in the temporary directory, and then returns the file name. However, the name of this file is only used to help build $filePath, which is used for the resized images, and is later moved to the final location. Unfortunately, the original empty file created by the tempnam function is never used or cleaned up, and it gets left behind.

On uploading file through Stapler I get Symfony \ Component \ HttpFoundation \ File \ Exception \ FileNotFoundException The file "1.png" does not exist

Hi,

I have been using Stapler for ages now.

All of a sudden I get the error above when uploading files now on my local machine.

Is this a bug? Here is the stack trace from the log file:

[2014-05-28 09:40:21] local.ERROR: exception 'Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException' with message 'The file "1.png" does not exist' in /Freelance/Current Projects/mbm-site/laravel/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/File/File.php:41
Stack trace:
#0 /Freelance/Current Projects/mbm-site/laravel/vendor/codesleeve/stapler/src/Codesleeve/Stapler/IOWrapper.php(96): Symfony\Component\HttpFoundation\File\File->__construct('1.png', '1.png')
#1 /Freelance/Current Projects/mbm-site/laravel/vendor/codesleeve/stapler/src/Codesleeve/Stapler/IOWrapper.php(29): Codesleeve\Stapler\IOWrapper->createFromString('1.png')
#2 /Freelance/Current Projects/mbm-site/laravel/vendor/codesleeve/stapler/src/Codesleeve/Stapler/Attachment.php(129): Codesleeve\Stapler\IOWrapper->make('1.png')
#3 /Freelance/Current Projects/mbm-site/laravel/vendor/codesleeve/stapler/src/Codesleeve/Stapler/Stapler.php(123): Codesleeve\Stapler\Attachment->setUploadedFile('1.png')
#4 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(340): Post->setAttribute('hero_image', '1.png')
#5 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1326): Illuminate\Database\Eloquent\Model->fill(Array)
#6 /Freelance/Current Projects/mbm-site/laravel/app/controllers/PostsController.php(157): Illuminate\Database\Eloquent\Model->update(Array)
#7 [internal function]: PostsController->update('85')
#8 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(231): call_user_func_array(Array, Array)
#9 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(93): Illuminate\Routing\Controller->callAction('update', Array)
#10 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(62): Illuminate\Routing\ControllerDispatcher->call(Object(PostsController), Object(Illuminate\Routing\Route), 'update')
#11 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(934): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'PostsController', 'update')
#12 [internal function]: Illuminate\Routing\Router->Illuminate\Routing{closure}('85')
#13 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php(105): call_user_func_array(Object(Closure), Array)
#14 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1000): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#15 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(968): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#16 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(738): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#17 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(708): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#18 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Http/FrameGuard.php(38): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#19 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Illuminate\Http\FrameGuard->handle(Object(Illuminate\Http\Request), 1, true)
#20 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#21 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#22 /Freelance/Current Projects/mbm-site/laravel/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#23 /Freelance/Current Projects/mbm-site/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(606): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#24 /Freelance/Current Projects/mbm-site/laravel/public/index.php(49): Illuminate\Foundation\Application->run()
#25 /Freelance/Current Projects/mbm-site/laravel/server.php(19): require_once('/Freelance/Curr...')
#26 {main} [] []

Cheers,
Mark

s3 configuration

Travis,

If I set the default s3 configuration to contain the path settings and the access keys I need to use for my s3 space, do I need to specify this configuration again in the model for each file upload? If my global s3 configurations are set to what I want them to be can I just specify the s3 filesystem as the filesystem to use?

for instance:

public function __construct(array $attributes = array()) 
{

    $this->hasAttachedFile('imgfile', [
        'styles' => [ 'large' => '980x550', 'medium' => '640x360', 'thumbnail' => '230x130' ],
        'storage' => 'filesystem'           
    ]);

    $this->hasAttachedFile('mp3file', [
        'styles' => [],
        'storage' => 's3'
    ]);

    $this->hasAttachedFile('mp4file', [
        'styles' => [],
        'storage' => 's3'           
    ]);

    $this->hasAttachedFile('pdffile', [
        'styles' => [],
        'storage' => 's3'           
    ]);

    parent::__construct($attributes);

}

how to avoid creating images on every seed

during development, i'm testing things out and re-seeding the database often. However now that i've got stapler installed, each time I create a new entity on a model, all attached images are being processed - greatly slowing things down. is there a workaround for this?

Support for files which were not directly uploaded

Hi,
is there a way to attach files that have not been directly uploaded? e.g. they're somewhere on the filesystem already (let's assume some temporary folder) and I would like to attach them to the model. I've tried to create an instance of Symfony\Component\HttpFoundation\File\File
and then constructing new instance of Symfony\Component\HttpFoundation\File\UploadedFile
Using the info from the File object, but for some reason, the moment when i try to assign this created file to model, execution just stops, no exception, no error, just blank page and from network panel I can see a 500 response from server. Taking files directly from Input::file() works, but I'm uploading files through plupload (through AJAX) and at the moment of uploading, i do not have the instance of model yet.

I compared the object from Input::file() and the object I created, and they are the same, except for path, so maybe this is the reason?

Can you point me to right direction? Or this isn't possible at all?

Thanks in advance,

[Help] Image does not get written to file system

Well, here we go again: I have yet another file system issue.

I am using Stapler in two cases: For the Avatar changing and for the user galleries. When I upload an avatar and save my profile the file gets uploaded and processed like it should. I am using the below code for this:

    public function update()
    {
        $user = Confide::user();
        $user->nickname = Input::get('nickname');
        $user->about = Input::get('about');

        $avatarFile = Input::file('avatar');

        if($avatarFile !== null)
        {
            $user->avatar = $avatarFile;
        }

        if(!$user->updateUniques()) {
            Notification::danger($user->errors()->all());
        }

        return Redirect::action('user.profile', $user->getPresenter()->id);
    }

For the galleries it's somehow not working. I don't quite know why, but it somehow stopped working - for absolutely no reasons, I did not change anything on the webserver nor the upload code. I am using the following code for the picture uploads:

    public function upload($hashId)
    {
        try {
            $gallery = Gallery::findOrFail($this->getId($hashId));

            $picture = new Picture;
            $picture->picture = Input::file('file');
            $picture->gallery()->associate($gallery);

            if ($picture->save())
            {
                return Response::json($picture->toArray(), 200);
            }

            return Response::make('Could not upload image', 500);

        } catch (ModelNotFoundException $ex) {
            return Response::make('Gallery does not exist', 500);
        }
    }

When the avatar saves it also creates all the needed subfolders. When the picture gets uploaded it doesn't create the folders. I already checked, and yes indeed, I do have the right permissions set: drwxrwxrwx 1 vagrant vagrant.

Why has this code somehow stopped working? I haven't updates stapler either ... It's a mystery to me.

Version numbering

I know that stapler is still in beta, but in order to allow wildcarding of semantic versions.

In order to ride updates you have to require dev-master instead of being able to require ~1 or 1.0.*

Unexpected error

Travis,

I am running into a problem with my site (no worries - it's still in development) but, the problem I ran into started happening when I created an add-on domain. I needed to do this with my provider so I could specify the root directory of the site to be the public directory of laravel.

Anyway, after this configuration took place I started getting this error:

Symfony \ Component \ Debug \ Exception \ FatalErrorException
syntax error, unexpected '['

Referencing this file:

Symfony\Component\Debug\Exception\FatalErrorException
…/­vendor/­codesleeve/­stapler/­src/­Codesleeve/­Stapler/­StaplerServiceProvider.php line:118

I thought it might be a problem with the class not resolving correctly so I tries to update the class files with composer using composer update and during the update I received this error:

Generating autoload files
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"syntax error, unexpected '['","file":"/home/damascu1/drccweb/vendor/codesleeve/stapler/src/Codesleeve/Stapler/StaplerServiceProvider.php","line":118}}{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"syntax error, unexpected '['","file":"/home/damascu1/drccweb/vendor/codesleeve/stapler/src/Codesleeve/Stapler/StaplerServiceProvider.php","line":118}}Script php artisan clear-compiled handling the post-update-cmd event returned with an error

any advice?

Stapler in non-User model

I am running into an issue with Stapler in a non-User model. Stapler is working fine with my User model and I am able to create and update my avatar. But, I have a Marquee model with the attachment Image and am getting the following error when trying to create or update with a file attachment.

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'image' in 'field list' (
SQL: update `marquees` set `updated_at` = ?, `image_file_name` = ?, `image_file_size` = ?, 
`image_content_type` = ?, `image_updated_at` = ?, `image` = ? where `id` = ?
) 
(Bindings: array (
0 => '2013-09-20 09:54:03', 1 => myimage.jpg', 2 => 1624378, 3 => 'image/jpeg', 
4 => '2013-09-20 09:54:03', 5 => Symfony\Component\HttpFoundation\File\UploadedFile::__set_state(
array(
 'test' => false, 'originalName' => 'myimage.jpg', 'mimeType' => 'image/jpeg',
 'size' => 1624378, 'error' => 0, 
)), 6 => '6', 
)) 

=== Controller Update function ===

public function update($id)
{
    $input = array_except(\Input::all(), '_method');

    $validation = \Validator::make($input, \Marquee::$rules);

    if ($validation->passes())
    {
        $marquee = $this->marquee->find($id);
        if(\Input::hasFile('image')){
            $marquee->image = \Input::file('image');
        }
        $marquee->update($input);

        return \Redirect::route('admin.marquees.show', $id);
    }

    return \Redirect::route('admin.marquees.edit', $id)
        ->withInput()
        ->withErrors($validation)
        ->with('message', 'There were validation errors.');
}

File Upload Progress?

Hello, I was wondering if this package supported the tracking of the upload progress while uploading to S3? Considering I use any of the top jquery plugins that support that feature? Thank you.

[Proposal] Accept DataURLs from Javascript

It would be nice to be able to upload XHR file requests from javascript using the Filereader.readAsDataURL functionality directly into stapler.

From what I've read, readAsDataURL formats the file as a base64 encoded string with extra meta-data on the front end of things. It's formatted a bit like data:[<MIME-type>][;charset=<encoding>][;base64],<data>

I think that it would be possible to add a regex that matches strings that start with data. I know that there is this package to decipher data URI's into something a bit more usable. I'm checking to see if there's a way to shim this into a Symfony uploaded file object to pull the responsibility out of Stapler.

[Help] User profile picture + picture collection

I am trying to get the following done with stapler:

  • A user hasMany pictures User::pictures()
  • A user hasOne profile picture from the picture collection User::profilePicture()

I got the pictures working, but the avatar / profile picture gives me headaches. I tried several combinations, but none of them worked. How do I get the default avatar when the user hasn't set one yet? The hasOne relationship returns NULL - not really helpful, since I set the default avatar in the ProfilePicture model.

Considerable performance problems using S3 backend

I'm running stapler with a S3 backend and since implementing stapler I've noticed considerable lag in my application. After running xhprof over my laravel app and digging my way down through the rabbit hole I found out that for every attachment->url() call stapler seems to do a S3->bucketExists() call.
This seems to generate a guzzle request over the S3 API to check if the bucket exists. When doing this for say 50 images on a page this will result in a lot of curl requests and is really slowing the application down.

What is your opinion on this?

Multiple attached images

Can the hasAttachedFile method handle an array of files? I have a Project model that has two file uploads: Logo and Banner. Obviously both are for different types of images.

Filename Slug

This package is extremely useful, however still miss something.
The Laravel possuim one function to create slugs, Str::slug() and I think it would be interesting to add this option to rename the images, that way it would be possible to follow a more defined pattern.

$this->hasAttachedFile('image', array(
    'styles' => array(
        'slug' => true,
    ),
));

In this case, something like Image Name_test.jpg would look like image-name-test.jpg

Interpolation error for default_url

config:
'default_url' => '/images/missing/:class/:attachment/:style/missing.:extension'

result: /images/missing/Place/logos/medium/missing.

=(

but it work for url:
'url' => '/upload/:class/:attachment/:id_partition/:style/:hash.:extension'

result: /upload/Place/logos/000/000/002/medium/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35.jpg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.