mprythero's avatar

Storage::put - External FTP Site

So I have run across an interesting issue and I am hoping someone might have run across this before or might have some advice for me.

For a project, with each item we get in, we upload an image of a document to an FTP site. At this point in time, it does successfully upload, however every now and then, what I want to call an "imaginary exception" comes up.

My controller action related to this issue is as such:

try{
                    Storage::disk('rrtsdrs-ftp')->put($proN, $file);
                }
                catch (\Exception $e) {
                    $errorMessage = $e->getMessage();

                    Mail::send('emails.response.agentRemitErrors', ['item' => $item], function($message) use ($item){
                        $message->from('*********', '***********');
                        $message->subject('DR Remit Exceptions - '. $item->pro_number);
                        $message->to('*****************');
                    });
                }

I put in this solely to notify me if something goes wonky and I need to reupload an image. However, whenever an exception notifies me, I learn that the image has in fact been successfully uploaded without an issue.

So I'm wondering if there is something else it could be. I'd appreciate any help anyone can provide.

Thanks!

0 likes
5 replies
devfrey's avatar

It would be helpful if you could provide us with more information about the exception you're getting. It could very well be a runtime exception that occurs during or after the file upload. That's why you're seeing the file anyway.

On a side note, I'd like to recommend Sentry.io. It will catch any uncaught exceptions and notify you about them. It easily integrates with Laravel: https://github.com/getsentry/sentry-laravel

lostdreamer_nl's avatar

Try and send the $errorMessage in the email as well.... it can at least tell you what is going wrong.

mprythero's avatar

@jangenent - I'll add the exception message next time it shows now that I've got it inserted into my email. However, I like what I see with your suggestion regarding sentry, so I think I'm going to work on incorporating it into my project as well. Thank you and I'll reply with the exact error message soon.

@lostdreamer_nl - Thanks for your suggestion, I've gone and done that and so now I'll wait and see what the error it is that it produces. Thanks!

mprythero's avatar

@jangenent and @lostdreamer_nl - I have finally come across the error again in my work and have the exception returned with it:

ftp_fput(): The process cannot access the file because it is being used by another process.

As I said though, the files are uploaded successfully, so I'm not exactly sure what to do at this moment...

lostdreamer_nl's avatar

I think the upload request is going twice, maybe the user (or a specific browser) has a slightly different way of uploading the file?

If the same file gets send twice by the same user (right after another) and you are not giving the file a unique filename, the second request would give this error while the first request uploads the file correctly.

What type of upload are you using? A simple file field in a form, or some AJAX way to upload them?

Please or to participate in this conversation.