dropzone.js doesnt upload .doc,.xls,.xlsx file formats - yii

i have use dropzone extension to upload images. it work like charm. but i want to upload document files doc,docx,xls,xlsx.
$this->widget('ext.dropzone.EDropzone', array(
'model' => $model,
'attribute' => 'image_name',
'url' => Yii::app()->request->baseUrl.'/jobMaster/ImageUpload',
'mimeTypes' => array('image/jpeg', 'image/png','image/jpg'),
'onSuccess' => 'succcesupload',
//'maxFilesize'=> 5,
'options' => array(
'addRemoveLinks'=> true,
'removedfile'=> "js:function(file) {
var name = file.name;
$.ajax({
type: 'POST',
url: '".$this->createUrl('/jobMaster/deleteImageUpload')."',
data: 'id='+name,
dataType: 'html'
});
var _ref;
return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
}"
)
));
But i don't know how to change in this widget.
i change
'mimeTypes' => array('image/jpeg', 'image/png','image/jpg','file/doc','file/xls','file/xlsx','file/docx'),
but it doesn't work. Any answer?

Here i got solution
'mimeTypes' => array('image/jpeg', 'image/png','image/jpg','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/docx','application/pdf','text/plain','application/msword','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),

Here i mentioned which mimeType is used for which extension.
For .docx -
application/vnd.openxmlformats-officedocument.wordprocessingml.document
For .xlxs -
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
For .doc - application/msword
Here is full list for MIME types of different file extensions.

I found issue with .docx, a console.log() of the mime type returned this:
application/vnd.openxmlformats-officedocument.wordprocessingml.d
Hope that helps someone. It fixed the issue for me

Related

Access Custom S3 Metadata After Completing Multipart Upload

I'm wanting to access the custom metadata for an object uploaded via the S3 multipart upload after firing off the completeMultipartUpload method.
I initiate a multipart S3 upload with some added custom metadata like so:
$response = $this->client->createMultipartUpload([
'Bucket' => $this->bucket,
'Key' => $key,
'ContentType' => $type,
'Expires' => 60,
'Metadata' => [
'file-guid' => $fileGuid,
],
]);
When I complete the multipart upload, I'm wanting to access the file-guid metadata and pass it along in my response.
$result = $this->client->completeMultipartUpload([
'Bucket' => $this->bucket,
'Key' => $key,
'UploadId' => $uploadId,
'MultipartUpload' => [
'Parts' => $parts,
],
]);
$fileGuid = $result['?'] // Couldn't find the metadata in the result.
return response()->json(['file-guid' => $fileGuid]);
I've checked the S3 object after it's been uploaded and it shows the custom metadata, but I don't see how to access it. I assumed it would be part of the completeMultipartUpload response, but I'm not seeing it.
Any help would be appreciated. Thanks!
I found a solution, but it involves an additional request. If anyone knows of a way to access the metadata without making another request, that would be better.
$headObject = $this->client->headObject([
'Bucket' => $this->bucket,
'Key' => $key,
]);

I need help when I try to upload an image CodeIgnite4

I need help when I try to upload an image
I get this error and I don't understand why
avatar is not a valid uploaded file.
my code in controller
rules:
'avatar' => [
'rules' => 'required|uploaded[avatar]|max_size[avatar,1024]|ext_in[avatar,jpg,jpeg,png]',
'errors' => [
'required' => lang('Core.Auth.Error.required'),
]
],
upload:
if (!$this->validate($rules)) {
$data['validation'] = $this->validator;
} else {
$avatar = $this->request->getFile('avatar');
$newName = $avatar->getRandomName();
$avatar->move(WRITEPATH.'uploads', $newName);
$filepath = base_url()."/selfie/".$newName;
my php.ini
upload_max_filesize = 1G
post_max_size = 1G
memory_limit = 1G
From CodeIgniter documentation:
The uploaded rule fails if the name of the parameter does not match the name of any uploaded files.
The exact error message you posted will appear if this rule cannot be satisfied
Double check your HTML <input> tag and make sure that both name attribute of this tag and the name passed to uploaded rule are the same, e.g.:
// In the HTML
<input type="file" name="avatar">
// In the controller
$this->validate([
'avatar' => 'required|uploaded[avatar]|max_size[avatar,1024]|ext_in[avatar,jpg,jpeg,png]'
]);

When i download file programmatically from s3 bucket, It gives me error It looks like we don't support this file format

When I download file from s3 bucket, I am using aws-sdk for that, it downloads the files but when i open that file it says It looks like we don't support this file format, here is my full code of it, can anyone please check my code and help me why image is doesn't open the image, my wholde code is in PHP, It looks like small error but doesn't working for me
$bucket = '*****';
$keyname = '1560346461616.jpg';
$s3 = new S3Client([
'version' => 'latest',
'region' => '******',
'credentials' => [
'key' => '******',
'secret' => '******',
],
]);
$result = $s3->getObject([
'Bucket' => $bucket,
'Key' => $keyname,
]);
header("Content-Type: {$result['ContentType']}");
header('Content-Disposition: attachment; filename='.$keyname);
echo $result['Body'];
} catch (Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
Check the content type of your .jpg file stored in s3. Ensure the metadata for this object says image/jpeg.I don't think it is related to the object you downloaded,maybe the download file was corrupted.

AWS PHP SDK ContentType not being set

When uploading to S3 via PHP SDK even after setting the correct ContentType S3 still shows application/octet-stream
$file = Aws::putObject([
'Bucket' => 'types-jpeg',
'Key' => 'current.jpg',
'SourceFile' => 'uploads/current.jpg',
'ContentType' => 'image/jpeg',
'ACL' => 'public-read',
]);
File successfully uploads except that viewing the file's meta data shows application/octet-stream instead of 'image/jpeg' on its Content-Type
Any ideas?

YouTube API Upload Video as 'Unlisted' or 'Private'?

I am using a Wordpress plugin called 'YouTube Uploader', it allows you to upload YouTube videos from your WordPress site, it is working for me but the only issue is that it uploads the videos as Public and I need them to go up as Unlisted or Private (either will do). If someone could tell me what to add/change to make it do this, it would be greatly appreciated, thanks!
I uploaded the code to Pastebin as I didn't want to fill this entire post with code, heres the link: http://pastebin.com/GfQjhiiq
Thanks!
I'm not that clued up on Wordpress but what you're looking for is a tag called <yt:private/>
<yt:private/> is a child of media:group so a sample xml schema could look something like the following. (Note where <yt:private/> sits within the code block):
<media:group>
<media:title type="plain">Title here</media:title>
<media:description type="plain">Description here</media:description>
<media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Travel</media:category>
<media:keywords>keyword1</media:keywords>
<yt:private/>
</media:group>
Hope this is of some use.
I think this method is pretty outdated. But there is a work around if you were to use the the Plain PHP API method...
This Part does the trick:
// unlisted upload
$accessControlElement = new Zend_Gdata_App_Extension_Element('yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', '');
$accessControlElement->extensionAttributes = array(
array(
'namespaceUri' => '',
'name' => 'action',
'value' => 'list'
),
array(
'namespaceUri' => '',
'name' => 'permission',
'value' => 'denied'
));
$myVideoEntry->extensionElements = array($accessControlElement);
In the bigger scheme:
$this->Zend->loadClass('Zend_Gdata_ClientLogin');
$this->Zend->loadClass('Zend_Gdata_YouTube');
$client = Zend_Gdata_ClientLogin::getHttpClient(ZEND_GDATA_CLIENT_EMAIL, ZEND_GDATA_CLIENT_PASS, 'youtube');
$client->setHeaders('X-GData-Key', "key=".ZEND_GDATA_YOUTUBE_DEVELOPER_KEY);
$yt = new Zend_Gdata_YouTube($client);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
// unlisted upload
$accessControlElement = new Zend_Gdata_App_Extension_Element(
'yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', ''
);
$accessControlElement->extensionAttributes = array(
array(
'namespaceUri' => '',
'name' => 'action',
'value' => 'list'
),
array(
'namespaceUri' => '',
'name' => 'permission',
'value' => 'denied'
));
$myVideoEntry->extensionElements = array($accessControlElement);
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
$myVideoEntry->setVideoCategory('Sports');
The whole Gist is over here: https://gist.github.com/1044349