Created
September 5, 2018 12:50
-
-
Save adnanhz/5e3abec7c6377af2b1321ed0cd8d9dec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function uploadFile (url, blob) { | |
return fetch(url, { | |
method:'POST', | |
body: blob // also tried appending the blob to formData | |
}).then(response => { | |
if(response.ok){ | |
return response.json(); | |
} else { | |
throw response; | |
} | |
}); | |
} | |
onTakePhoto (dataUri) { | |
const blob = toBlob(dataUri); | |
this.uploadFile('/upload', blob); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function blobUpload(Request $request){ | |
$pathresolver = new \FileUpload\PathResolver\Simple($_SERVER['DOCUMENT_ROOT'].env('temp_location')); | |
$filesystem = new \FileUpload\FileSystem\Simple(); | |
$fileupload = new \FileUpload\FileUpload(file_get_contents('php://input'), $_SERVER); | |
$filenamegenerator = new \FileUpload\FileNameGenerator\Random(5); | |
$fileupload->setPathResolver($pathresolver); | |
$fileupload->setFileSystem($filesystem); | |
$fileupload->setFileNameGenerator($filenamegenerator); | |
list($files, $headers) = $fileupload->processAll(); | |
$fileName = $this->generateRandomString(); | |
return response()->json(env('SERVER_IP').'/temp/'.$fileName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment