@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Detect the MIME type of large files by examining the first chunk

Summary:
Fixes T11242. See that task for detailed discussion.

Previously, it didn't particularly matter that we don't MIME detect chunked files since they were all just big blobs of junk (PSDs, zips/tarballs, whatever) that we handled uniformly.

However, videos are large and the MIME type also matters.

- Detect the overall mime type by detecitng the MIME type of the first chunk. This appears to work properly, at least for video.
- Skip mime type detection on other chunks, which we were performing and ignoring. This makes uploading chunked files a little faster since we don't need to write stuff to disk.

Test Plan:
Uploaded a 50MB video locally, saw it as chunks with a "video/mp4" mime type, played it in the browser in Phabricator as an embedded HTML 5 video.

{F1706837}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11242

Differential Revision: https://secure.phabricator.com/D16204

+26 -5
+24 -1
src/applications/files/conduit/FileUploadChunkConduitAPIMethod.php
··· 51 51 $start, 52 52 $start + $length); 53 53 54 + // If this is the initial chunk, leave the MIME type unset so we detect 55 + // it and can update the parent file. If this is any other chunk, it has 56 + // no meaningful MIME type. Provide a default type so we can avoid writing 57 + // it to disk to perform MIME type detection. 58 + if (!$start) { 59 + $mime_type = null; 60 + } else { 61 + $mime_type = 'application/octet-stream'; 62 + } 63 + 54 64 // NOTE: These files have a view policy which prevents normal access. They 55 65 // are only accessed through the storage engine. 56 66 $chunk_data = PhabricatorFile::newFromFileData( ··· 58 68 array( 59 69 'name' => $file->getMonogram().'.chunk-'.$chunk->getID(), 60 70 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 71 + 'mime-type' => $mime_type, 61 72 )); 62 73 63 74 $chunk->setDataFilePHID($chunk_data->getPHID())->save(); 75 + 76 + $needs_update = false; 64 77 65 78 $missing = $this->loadAnyMissingChunk($viewer, $file); 66 79 if (!$missing) { 67 - $file->setIsPartial(0)->save(); 80 + $file->setIsPartial(0); 81 + $needs_update = true; 82 + } 83 + 84 + if (!$start) { 85 + $file->setMimeType($chunk_data->getMimeType()); 86 + $needs_update = true; 87 + } 88 + 89 + if ($needs_update) { 90 + $file->save(); 68 91 } 69 92 70 93 return null;
+2 -4
src/applications/files/storage/PhabricatorFile.php
··· 270 270 271 271 $file->setByteSize($length); 272 272 273 - // TODO: We might be able to test the first chunk in order to figure 274 - // this out more reliably, since MIME detection usually examines headers. 275 - // However, enormous files are probably always either actually raw data 276 - // or reasonable to treat like raw data. 273 + // NOTE: Once we receive the first chunk, we'll detect its MIME type and 274 + // update the parent file. This matters for large media files like video. 277 275 $file->setMimeType('application/octet-stream'); 278 276 279 277 $chunked_hash = idx($params, 'chunkedHash');