Track an upload status
@param int $FileUploadId
@return models\FileSystem\FileUpload
@throws \GuzzleHttp\Exception\GuzzleException
@throws \alphayax\freebox\Exception\FreeboxApiException
345327
public function getFromId($FileUploadId)
    {
        $rest = $this->callService('GET', self::API_UPLOAD . $FileUploadId);

        return $rest->getModel(models\FileSystem\FileUpload::class);
    }
289953
public function uploadPartToAmazon(
        $filePath,
        $uploadEndpoint,
        $uploadRequestInfo,
        $chunkNumber,
        $chunk,
        $numberOfChunks
    ) {
        $finalKey = sprintf("%s/p%d", $uploadRequestInfo['multipart_params']['key'], $chunkNumber);
        $formData = [
            self::getFormDataParams('x-amz-credential', $uploadRequestInfo['multipart_params']['x-amz-credential']),
            self::getFormDataParams('X-Amz-Signature', $uploadRequestInfo['multipart_params']['X-Amz-Signature']),
            self::getFormDataParams('x-amz-algorithm', $uploadRequestInfo['multipart_params']['x-amz-algorithm']),
            self::getFormDataParams('x-amz-date', $uploadRequestInfo['multipart_params']['x-amz-date']),
            self::getFormDataParams('Policy', $uploadRequestInfo['multipart_params']['Policy']),
            self::getFormDataParams('key', $finalKey),
            self::getFormDataParams('acl', $uploadRequestInfo['multipart_params']['acl']),
            self::getFormDataParams('success_action_status',
                $uploadRequestInfo['multipart_params']['success_action_status']),
            self::getFormDataParams('Content-Type', $uploadRequestInfo['multipart_params']['Content-Type']),
            self::getFormDataParams('name', $filePath),
            self::getFormDataParams('chunk', $chunkNumber),
            self::getFormDataParams('chunks', $numberOfChunks),
            self::getFormDataParams('Filename', $finalKey),
            self::getFormDataParams('file', $chunk)
        ];

        $stack = HandlerStack::create(new CurlHandler());
        $oauthRequestClient = new Client([
            'base_uri' => $uploadEndpoint,
            'handler' => $stack,
        ]);

        return $oauthRequestClient->postAsync($uploadEndpoint, ['multipart' => $formData])
            ->then(
                function (ResponseInterface $response) {
                    return json_decode($response->getBody(), true);
                }
            );
    }
660701
public function updateFile($fileId, array $data)
    {
        $xml = "<file>";

        if (isset($data['name'])) {
            $xml .= "<name>{$data['name']}</name>";
        }

        if (isset($data['categoryId'])) {
            $xml .= "<categoryId>{$data['categoryId']}</categoryId>";
        }

        if (isset($data['shareWithEmployee'])) {
            $xml .= "<shareWithEmployee>{$data['shareWithEmployee']}</shareWithEmployee>";
        }

        $xml .= "</file>";

        return $this->post("files/{$fileId}", $xml);
    }
1081464
public function callbackAddImageToIndex($fileId)
    {
        $image = Yii::$app->storage->addImage($fileId);
        
        if (!$image) {
            return $this->sendError("Unable to create image from given file Id.");
        }

        Yii::$app->db->createCommand()->insert($this->refTableName, $this->prepareInsertFields([
            $this->imageIdFieldName => (int) $image->id,
            $this->refFieldName => (int) $this->itemId,
        ]))->execute();

        return $this->getImageArray($image->id);
    }
273944
public function removeAction($fileId = null)
    {
        if (!$fileId) {
            return new Response('Please provide a file id', 500);
        }

        $manager = $this->getDoctrine()->getManager();
        $repo = $this->getDoctrine()->getRepository('LibrinfoMediaBundle:File');

        $file = $repo->findOneBy([
            'id'    => $fileId,
        ]);

        if ($file !== null) {
            if ($file->isOwned()) {
                $dispatcher = $this->get('event_dispatcher');
                $event = new GenericEvent($file);
                $dispatcher->dispatch(UploadControllerEventListener::REMOVE_ENTITY, $event);
            }

            $name = '' . $file->getName();
            $manager->remove($file);
            $manager->flush();

            return new Response($name . ' removed successfully', 200);
        } else {
            return new Response('the file cannot be removed', 401);
        }
    }
1240747
public function fileLookup($fileId) {
		$member = $this->securityContext->getMember();
		if (!$member) {
			return;
		}
		
		$file = File::get()->filter(array('ID' => $fileId, 'OwnerID' => $member->ID))->first();
		if ($file && $file->ID) {
			return array(
				'Title'		=> $file->Title,
				'Link'		=> $file->getAbsoluteURL(),
				'IsImage'	=> $file instanceof Image,
				'ID'		=> $file->ID,
			);
		}
	}
50054
public function upload(UploadedFile $uploadedFile, $id = null)
    {
        if ($this->validatesUploadedFile())
        {
            $this->validateUploadedFile($uploadedFile);
        }

        return $this->processUpload($uploadedFile, $id);
    }
397153
public function upload(Request $request, $dirId)
    {

        try {

            $folder = $this->getDirOrFail($dirId);

            if (!$request->hasFile('uploadedFile')) {
                throw new RuntimeException('Uploaded File not found');
            }

            $uploadedFile = $request->file('uploadedFile');

            /** @var UploadedFile $uploadedFile */
            $uploadedFile = is_array($uploadedFile) ? $uploadedFile[0] : $uploadedFile;

            $fileName = $uploadedFile->getClientOriginalName();

            $newPath = $this->getTempDir() . '/' . $fileName;

            $uploadedFile->move($this->getTempDir(), $fileName);

            $this->fileDB->importFile($newPath, $folder);

            return $this->redirectTo('index', $folder->getId());

        } catch(FileException $e) {
            $this->flashMessage('upload-failed','danger');
        } catch(RuntimeException $e) {
            $this->flashMessage('uploaded-file-missing','danger');
        }

        return $this->redirectTo('index');

    }
611937
protected function updateFile($file_id)
    {
        if (!$this->isError() && !$this->file->update($file_id, $this->getSubmitted())) {
            $this->errorAndExit($this->text('Unexpected result'));
        }
    }
49027
public function syncFiles($contentId)
    {
        $block = $this->repository->getById($contentId);
        if (empty($block)) {
            return $this->respondNotFound();
        }
        $this->authorize('update', $block);
        $input = $this->validator->validate('syncFiles');
        $block = $this->fileRepository->syncWith($block, $this->buildSyncData($input));
        return $this->respondWithSuccess($block);
    }
876720
public static function getUploadProgress($uniqueId) {
		
		$upload = apc_fetch('upload_' . $uniqueId);
		if ($upload['done']) {
			$percent = 100;
		} else if (0 == $upload['total']) {
			$percent = 0;
		} else {
			$percent = round(($upload['current'] / $upload['total'] * 100), 0);
		}
		return $percent;
		
	}
102646
protected function parseFileID($fileID)
    {
        /** @var ParsedFileID $parsedFileID */
        $parsedFileID = $this->getProtectedResolutionStrategy()->parseFileID($fileID);
        return $parsedFileID ? $parsedFileID->getTuple() : null;
    }
43208
public function upload($uuid = null)
    {
        if ($uuid) {
            // strip everything but valid UUID chars
            $uuid = preg_replace('/[^a-z\-0-9]/', '', $uuid);
        } else {
            $uuid = Text::uuid();
        }

        $options = [
            'upload_dir' => Configure::read('Attachments.tmpUploadsPath') . DS . $uuid . DS,
            // FIXME Make file paths configurable
            'accept_file_types' => Configure::read('Attachments.acceptedFileTypes')
        ];

        $uploadHandler = new \UploadHandler($options);
        exit;
    }
240698
public function update($id){
    
        try {
            $file = $this->file->find($id);            
            $file->filename = Input::get('filename');
            $file->save();

            return response()->json([
                'status' => 'success'
            ]);
        } 

        catch (Exception $e) {
            return $this->handleError($e);
        }
    }
1309810
public function download($attachmentId = null)
    {
        $attachment = $this->Attachments->get($attachmentId);

        $this->_checkAuthorization($attachment);

        $this->response->file($attachment->getAbsolutePath(), [
            'download' => true,
            'name' => $attachment->filename
        ]);
        return $this->response;
    }
3540
public function find($fileId, $type = null)
	{
		if (! is_string($fileId)) {
			return null;
		}

		if (empty($type)) {
			$type = FileAbstraction::CN();
		}
		
		return $this->getDoctrineEntityManager()
				->find($type, $fileId);
	}
885256
private function uploadFile(UploadedFile $file)
    {
        /** @var FileStorage $fileStorage */
        $fileStorage = Yii::$app->get('fileStorage');

        $filename = $fileStorage->saveUploadedFile($file);

        return $fileStorage->put($filename, $file->name);
    }