Merge pull request #4363 from owncloud/fix-4355

Send mime-type for new files
This commit is contained in:
Thomas Müller 2013-08-14 09:46:10 -07:00
commit b3b2b2d64c
1 changed files with 16 additions and 11 deletions

View File

@ -54,6 +54,8 @@ function progress($notification_code, $severity, $message, $message_code, $bytes
}
}
$target = $dir.'/'.$filename;
if($source) {
if(substr($source, 0, 8)!='https://' and substr($source, 0, 7)!='http://') {
OCP\JSON::error(array("data" => array( "message" => "Not a valid source" )));
@ -62,7 +64,6 @@ if($source) {
$ctx = stream_context_create(null, array('notification' =>'progress'));
$sourceStream=fopen($source, 'rb', false, $ctx);
$target=$dir.'/'.$filename;
$result=\OC\Files\Filesystem::file_put_contents($target, $sourceStream);
if($result) {
$meta = \OC\Files\Filesystem::getFileInfo($target);
@ -75,20 +76,24 @@ if($source) {
$eventSource->close();
exit();
} else {
$success = false;
if($content) {
if(\OC\Files\Filesystem::file_put_contents($dir.'/'.$filename, $content)) {
$meta = \OC\Files\Filesystem::getFileInfo($dir.'/'.$filename);
$id = $meta['fileid'];
OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id)));
exit();
}
}elseif(\OC\Files\Filesystem::touch($dir . '/' . $filename)) {
$meta = \OC\Files\Filesystem::getFileInfo($dir.'/'.$filename);
$success = \OC\Files\Filesystem::file_put_contents($target, $content);
} else {
$success = \OC\Files\Filesystem::touch($target);
}
if($success) {
$meta = \OC\Files\Filesystem::getFileInfo($target);
$id = $meta['fileid'];
OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id, 'mime' => $meta['mimetype'])));
$mime = $meta['mimetype'];
OCP\JSON::success(array('data' => array(
'id' => $id,
'mime' => $mime,
'content' => $content,
)));
exit();
}
}
OCP\JSON::error(array("data" => array( "message" => "Error when creating the file" )));