0
votes

Using laravel-stapler, my laravel eloquent model is trying to save an attachment to S3. S3 Configuration has been set and are being picked up properly by the laravel-stapler package.

Here's my eloquent model:

use Codesleeve\Stapler\ORM\StaplerableInterface;
use Codesleeve\Stapler\ORM\EloquentTrait;

class SwiftDocument extends Eloquent implements StaplerableInterface{

use Illuminate\Database\Eloquent\SoftDeletingTrait;

use EloquentTrait;

protected $table = "swift_document";

protected $guarded = array('id');

protected $fillable = ["document_file_name","document_file_size","document_content_type","document_updated_at","user_id"];

public $timestamps = true;

protected $dates = ['deleted_at'];

public function __construct(array $attributes = array())
{
    // Define an attachment named 'document' that stores files locally.
    $this->hasAttachedFile('document', [
        'storage' => 's3',
        'url' => '/upload/:attachment/:id/:filename',
        'default_url' => '/defaults/:style/missing.png',
        'keep_old_files' => true            
    ]);
    
    parent::__construct($attributes);
}

/*
 * Event Observers
 */

public static function boot() {
    parent:: boot();
    
    /*
     * Set User Id on Save
     */
    static::saving(function($model){
        $model->user_id = Sentry::getUser()->id;
    });

    static::bootStapler();
    
}   
....

Upon saving an attachment, the following error is being thrown (in JSON format since it was an ajax call):

{"error":{"type":"Aws\S3\Exception\InvalidArgumentException","message":"","file":"/extvol/www/html/scottswift/http/vendor/aws/aws-sdk-php/src/Aws/Common/Exception/NamespaceExceptionFactory.php","line":91}}

As you can see the message part is blank.

Any thoughts on this?

1

1 Answers

1
votes

The 'ACL' key value for S3 Bucket config was wrongly set.

After reading the aws documentation found here, the uploads worked like a charm.