0

I am using this image library that uploads images to S3.

At first it saves the image as a temp file on local machine, then it uploads it to S3.

My issue is that using certain functions temp files get uploaded to C:\\xampp\\tmp/ and using other functions the temp file gets uploaded to C:\Users\myUser\AppData\Local\Temp.

My question is that where does this gets decided? and how to configure it?

I'm using Win10 machine and Postman.

This is the function that uploads the image to C:\Users\myUser\AppData\Local\Temp:

 * @param Request $request
 *
 * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded
 */
public function coverPhotoFromRequest( Request $request ) {
  if ( $request->hasFile( 'cover_photo' ) ) {
    $this->clearMediaCollection( 'cover' );
    $this->addMedia( $request->file( 'cover_photo' ) )->toMediaCollection( 'cover' );
  }
}

This very similar function uploads temp files to C:\\xampp\\tmp/:

/**
 * @helper handles the profile photo from request or link
 *
 * @param mixed $photo
 *
 * @return \Spatie\MediaLibrary\Media
 * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded
 * @throws \Spatie\MediaLibrary\FileAdder\FileDoesNotExist
 */
public function profilePhoto( $photo = null ) {
  if ( Ut::isUrl( $photo ) ) {
    return $this->clearMediaCollection( 'profile' )->addMediaFromUrl( $request->file( 'profile_photo' ) )->toMediaCollection( 'profile' );
  }

  if ( $photo instanceof UploadedFile ) {
    return $this->clearMediaCollection( 'profile' )->addMedia( $request->file( 'profile_photo' ) )->toMediaCollection( 'profile' );
  }
}

This is the path to project:

C:\Users\myUser\Projects\images\api

The problem is that when I push the code to the server, the same problem happens.

I checked config file and I have this:

'temporary_directory_path' => storage_path('medialibrary/temp'),

But sometimes it still sends to /xampp and C:\Users\myUser\AppData\

apokryfos
  • 38,771
  • 9
  • 70
  • 114
Seio. E.
  • 297
  • 2
  • 7
  • 18
  • 1
    what does the documentation say? It mentions a config file where a temp file location can be specified – Nick Maroulis Jul 02 '18 at 07:55
  • Thank you. I set it storage_path('medialibrary/temp') but it still behaves the same. I ran cache and config clear and composer dump-autoload – Seio. E. Jul 02 '18 at 08:10

1 Answers1

1

The library has a config directive for the temp path 'temporary_directory_path' listed in the docs https://docs.spatie.be/laravel-medialibrary/v7/installation-setup.

Does setting that help?

Phil Rennie
  • 376
  • 1
  • 6
  • Thank you. It is set to null and I set it to storage_path('medialibrary/temp') but still sends to locations outside project directory. – Seio. E. Jul 02 '18 at 08:08
  • Does the directory that storage_path('medialibrary/temp') resolves to actually exist? Have you checked the (error) logging to see if there are any 'folder does not exist' type messages? – Phil Rennie Jul 02 '18 at 11:54