tigerjun's avatar

Dropzone.js rename after upload success

I want my file name become unqiue therefore i can pass the file name to controller and delete the file by name. But i tried it a lot of way its doesnt work. Any idea how can i change the file name??

when it upload success

	myDropzone.on("success", function(response) {
		let newName = response.xhr.response;
		myDropzone.on("renameFile", function(response) {
			return newName;
		});
	});
0 likes
9 replies
bobbybouwmann's avatar

You should probably change the name of the file on the server and not in your JS code.

tigerjun's avatar

@bobbybouwmann I change it on server and i return the new file name. Now i want to rename the uploaded file name to the name i return.

	public function updateImg(Request $request){

			$image = $request->file('file');
			$imageName = time().'.'.$image->extension();
			$image->move(public_path('img/product/'),$imageName);

		   return response()->json($imageName);
		}
Snapey's avatar

are you trying to rename the file in the client computer? That would never be allowed.

tigerjun's avatar

@bobbybouwmann I tried this but its didnt work. Not sure where the file have been saved. Can i know what the different between this two??

$image->storeAs(public_path('img/product/'), $imageName);
Snapey's avatar

move() is correct as far as I am concerned

tigerjun's avatar

@snapey No. I only need to rename the file have been uploaded in the dropzone.

Snapey's avatar

so what wrong? what is not working

Snapey's avatar

ok, so move() is ok, but you have to tell it where the file is now, and where you want it to be. Bobby is correct, storeAs is easier to use

So if this did not work, is public_path set correctly

open tinker and type public_path('img/product/')

Please or to participate in this conversation.