Skip to content

Commit df4acfb

Browse files
committed
Use hash name for target filename
1 parent 48cbe00 commit df4acfb

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/Driver/ResumableJsUploadDriver.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,7 @@ private function saveChunk(UploadedFile $file, Request $request, StorageConfig $
169169
return new PercentageJsonResponse($range->getPercentage($chunks));
170170
}
171171

172-
$targetFilename = $filename;
173-
174-
// On windows you can not create a file whose name ends with a dot
175-
if ($file->getClientOriginalExtension()) {
176-
$targetFilename .= '.' . $file->getClientOriginalExtension();
177-
}
172+
$targetFilename = $file->hashName();
178173

179174
$path = $this->mergeChunks($config, $chunks, $targetFilename);
180175

tests/Driver/ResumableJsUploadDriverTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ public function testUploadLastChunk()
237237
{
238238
$this->createFakeLocalFile('chunks/200-0jWZTB1ZDfRQU6VTcXy0mJnL9xKMeEz3HoSPU0Zftxt', '000-099');
239239

240+
$file = UploadedFile::fake()->create('test.txt', 100);
240241
$request = Request::create('', Request::METHOD_POST, [
241242
'resumableChunkNumber' => 2,
242243
'resumableTotalChunks' => 2,
@@ -248,8 +249,7 @@ public function testUploadLastChunk()
248249
'resumableCurrentChunkSize' => 100,
249250
'resumableType' => 'text/plain',
250251
], [], [
251-
'file' => UploadedFile::fake()
252-
->create('test.txt', 100),
252+
'file' => $file,
253253
]);
254254

255255
/** @var \Illuminate\Foundation\Testing\TestResponse $response */
@@ -258,17 +258,18 @@ public function testUploadLastChunk()
258258
$response->assertJson(['done' => 100]);
259259

260260
Storage::disk('local')->assertExists('chunks/200-0jWZTB1ZDfRQU6VTcXy0mJnL9xKMeEz3HoSPU0Zftxt/100-199');
261-
Storage::disk('local')->assertExists('merged/200-0jWZTB1ZDfRQU6VTcXy0mJnL9xKMeEz3HoSPU0Zftxt.txt');
261+
Storage::disk('local')->assertExists($file->hashName('merged'));
262262

263-
Event::assertDispatched(FileUploaded::class, function ($event) {
264-
return $event->file = 'merged/200-0jWZTB1ZDfRQU6VTcXy0mJnL9xKMeEz3HoSPU0Zftxt.txt';
263+
Event::assertDispatched(FileUploaded::class, function ($event) use ($file) {
264+
return $event->file = $file->hashName('merged');
265265
});
266266
}
267267

268268
public function testUploadLastChunkWithCallback()
269269
{
270270
$this->createFakeLocalFile('chunks/200-0jWZTB1ZDfRQU6VTcXy0mJnL9xKMeEz3HoSPU0Zftxt', '000-099');
271271

272+
$file = UploadedFile::fake()->create('test.txt', 100);
272273
$request = Request::create('', Request::METHOD_POST, [
273274
'resumableChunkNumber' => 2,
274275
'resumableTotalChunks' => 2,
@@ -280,19 +281,19 @@ public function testUploadLastChunkWithCallback()
280281
'resumableCurrentChunkSize' => 100,
281282
'resumableType' => 'text/plain',
282283
], [], [
283-
'file' => UploadedFile::fake()->create('test.txt', 100),
284+
'file' => $file,
284285
]);
285286

286287
$callback = $this->createClosureMock(
287288
$this->once(),
288289
'local',
289-
'merged/200-0jWZTB1ZDfRQU6VTcXy0mJnL9xKMeEz3HoSPU0Zftxt.txt'
290+
$file->hashName('merged')
290291
);
291292

292293
$this->handler->handle($request, $callback);
293294

294-
Event::assertDispatched(FileUploaded::class, function ($event) {
295-
return $event->file = 'merged/200-0jWZTB1ZDfRQU6VTcXy0mJnL9xKMeEz3HoSPU0Zftxt.txt';
295+
Event::assertDispatched(FileUploaded::class, function ($event) use ($file) {
296+
return $event->file = $file->hashName('merged');
296297
});
297298
}
298299
}

0 commit comments

Comments
 (0)