Hoping I can get some help here. I am able to upload image files via the API, and I receive a file_id as a response, but every time I try to update an image field in an item using the id that was returned I get:
"File with mimetype application/octet-stream is not allowed, must match one of (MimeTypeMatcher('image', ('png', 'x-png', 'jpeg', 'pjpeg', 'gif', 'bmp', 'x-ms-bmp')),)
I've even added a line of code into my PHP script to pull the jpeg from file, rewrite it as a jpeg to be certain ( imagejpeg()) before uploading. Still, when I get to the point of updating the image field on the item, I get the same error. It seems all images uploaded via the API are converted to octet-stream. How do I get around this?
I'm using the Podio PHP library.
The PHP code is as follows:
$fileName = "testUpload.jpeg";
imagejpeg(imagecreatefromstring(file_get_contents($fileName)),$fileName);
$goFile = PodioFile::upload($fileName,$itemID);
$fileID = $goFile->file_id;
PodioItem::update((int)$itemID, array(
'fields' => array(
"logo" => (int)$fileID,
)
) , array(
"hook" => 0
));
Please try and replace :
$goFile = PodioFile::upload($fileName,$itemID);
with something like:
$goFile = PodioFile::upload('/path/to/example/file/example.jpg', 'example.jpg');
$fileID = $goFile->file_id;
PodioItem::update((int)$itemID, array(
'fields' => array(
"logo" => array((int)$fileID),
)
As it is described in https://developers.podio.com/examples/files#subsection_uploading
And then use $fileID as you've used. And yes, filename should have file extension as well, so it will not work with just 123123123 but should work well with 123123123.jpg
Related
I created a project with PHP Laravel and Vue JS. and configured it with Amazon AWS's basic plan. In the beginning, it worked well without any issues. But now, when I try to add a new blog post or edit already existed blog post with heavy content, it is showing 503 Service Unavailable error. I developed the algorithm for the blog as shown below.
Tables:
blogs - This table is used to store lightweight data of the post like title, featured image, URL, etc.
posts - This table is used to store the actual content of the post. It contains three columns like blog id, content, order. Here I am
using text datatype for content which will accept nearly 70k characters.
Algorithm:
When I submit a blog post, first it will create a row in the blogs table with lightweight data. And after that, the actual post content will be split into an array with each item contains 65k characters. And every item will be stored in the posts table as a new row with the blog id created in the blogs table. At the time of retrieving the post, it will join the rows in the posts table and will display the actual post.
Note: The above process is working fine without any issues.
Problem:
The actual problem is suddenly it started to show 503 error when I try to add a new post or edit the existed post with images(produces heavy amount of characters), even the post is being created in blogs table and incomplete amount of characters are adding in the posts table, while adding the rest of the content its showing 503 error.
Note: Even it is working fine on my localhost and another Bluehost server.
I tried to reduce the content splitting with 25k characters, but the result is showing the same.
if($request->hasFile('image')) {
$filenameWithExt = $request->file('image')->getClientOriginalName();
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
$extension = $request->file('image')->getClientOriginalExtension();
$fileNameToStore = 'post_' . time() . '.' .$extension;
$path = public_path('uploads/posts/' . $fileNameToStore);
if(!file_exists(public_path('uploads/posts/'))) {
mkdir(public_path('uploads/posts/'), 0777);
}
Image::make($request->file('image')->getRealPath())->resize(900, NULL)->save($path);
}else {
$fileNameToStore = NULL;
}
if($request->hasFile('author_image')) {
$filenameWithExt = $request->file('author_image')->getClientOriginalName();
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
$extension = $request->file('author_image')->getClientOriginalExtension();
$authorImage = 'author_' . time() . '.' .$extension;
$path = public_path('uploads/authors/' . $authorImage);
if(!file_exists(public_path('uploads/authors/'))) {
mkdir(public_path('uploads/authors/'), 0777);
}
Image::make($request->file('author_image')->getRealPath())->resize(50, 50)->save($path);
}else {
$authorImage = NULL;
}
$blog = Blog::create([
'title' => $request->title,
'image' => $fileNameToStore,
'category' => $request->category,
'meta_description' => $request->meta_description,
'meta_keywords' => $request->meta_keywords,
'url' => $request->url,
'meta_title' => $request->meta_title,
'author_name' => $request->author_name,
'author_image' => $authorImage,
'author_linkedin' => $request->author_linkedin,
'popular' => $request->popular
]);
$contents = str_split($request->post, 65000);
$i = 1;
foreach($contents as $key => $item)
{
Post::create([
'post' => $blog->id,
'content' => $item,
'order' => $i
]);
$i++;
}
I expect the output to be redirect back to blogs page with success message "Post has been created successfully", but the actual result is
Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
It looks like you need to increase values of post_max_size and upload_max_filesize in php.ini.
Guide for AWS: https://aws.amazon.com/ru/premiumsupport/knowledge-center/wordpress-themes-2mb/
I also recommend using transactions for your case. This will help to avoid partially created posts. https://laravel.com/docs/5.8/database#database-transactions
I want to delete an existing image from Cloudinary. I have fetched public id of that image but not working delete code.
\Cloudinary::config(array(
"cloud_name" => $cloud_name,//"demo",
"api_key" => $api_key,//"286877943699458",
"api_secret" => $api_secret//"gNr8jY6sCYyihv8mrcoJHq4AaAw"
));
$image1 = $image1_arr->public_id; //public id is present in image1_arr array
\Cloudinary\Uploader::destroy($image1);
Cloudinary's default type is upload. If you want to delete a fetched image, add the type to the destroy call -
\Cloudinary\Uploader::destroy($image1,array("type" => "fetch"));
If it's not the case, share the full error message for more details.
I am trying to upload vimeo files to a vimeo account via their PHP API.
This is my code ( we upload first to server in $[FILES][tmp_name] then we upload that file to vimeo with their php api ) -
$path = $_FILES['myfile']['tmp_name'];
$feedback = $vim->upload($path);
It works fine, just that I want it to be able to be uploaded with a title and a description.
Right now they are uploaded with the Untitled name.
There is no mention of title in their php api - https://github.com/vimeo/vimeo.php/blob/master/src/Vimeo/Vimeo.php
nor their api - https://developer.vimeo.com/api/upload/videos
Any ideas ?
Got it!
It's
$path = $_FILES['myfile']['tmp_name'];
$feedback = $vim->upload($path);
$vim->request($feedback, array(
'name' => 'ceva'
,'description' => 'alceva'
), 'PATCH');
I am working on a sample application in PHP to upload a picture to facebook and use that link to create a story. All is well except for the thumbnail is not showing up. Does anyone know if it is restricted to actually use the uploaded album image as a thumbnail?Below is the code i am using
$ret_obj = $facebook->api('/me/photos', 'POST', array(
'image' => '#'.realpath($photo),
'message' => $message,));
$imgId = $ret_obj['id'];
$objectjson = json_encode(array('title'=>'Sample','url'=>'http://facebook.com/photo.php?fbid='.$imgId,'description'=>'This is a sample','image'=>'http://facebook.com/photo.php?fbid='.$imgId));
$ret_obj = $facebook->api('/me/objects/xxxx:yyyy', 'POST', array(
'object' => $objectjson));
EDIT: Forgot to mention that i am using the suggested size image and any other images other than the uploaded ones can be used as thumbnail
I'm using Drupal 6.x and I'm writing a php class that will grab an RSS feed and insert it as nodes.
The problem I'm having is that the RSS feed comes with images, and I cannot figure out how to insert them properly.
This page has some information but it doesn't work.
I create and save the image to the server, and then I add it to the node object, but when the node object is saved it has no image object.
This creates the image object:
$image = array();
if($first['image'] != '' || $first['image'] != null){
$imgName = urlencode('a' . crypt($first['image'])) . ".jpg";
$fullName = dirname(__FILE__) . '/../../sites/default/files/rssImg/a' . $imgName;
$uri = 'sites/default/files/rssImg/' . $imgName;
save_image($first['image'], $fullName);
$imageNode = array(
"fid" => 'upload',
"uid" => 1,
"filename" => $imgName,
"filepath" => $uri,
"filemime" => "image/jpeg",
"status" => 1,
'filesize' => filesize($fullName),
'timestamp' => time(),
'view' => '<img class="imagefield imagefield-field_images" alt="' . $first['title'] . '" src="/' . $uri . '" /> ',
);
$image = $imageNode;
}
and this adds the image to the node:
$node->field_images[] = $image;
I save the node using
module_load_include('inc', 'node', 'node.pages');
// Finally, save the node
node_save(&$node);
but when I dump the node object, it no longer as the image. I've checked the database, and an image does show up in the table, but it has no fid. How can I do this?
Why not get the Feedapi, along with feedapi mapper, and map the image from the RSS field into an image CCK field you create for whatever kind of node you're using?
It's very easy, and you can even do it with a user interface.
Just enable feedapi, feedapi node (not sure on the exact name of that module), feedapi mapper, and create a feed.
Once you've created the feed, go to map (which you can do for the feed content type in general as well) on the feed node, and select which feed items will go to which node fields.
You'll want to delete your feed items at this point if they've already been created, and then refresh the feed. That should be all you need to do.
Do you need to create a separate module, or would an existing one work for you?
Are you using hook_nodeapi to add the image object to the node object when $op = 'prepare'?
If you read the comments on the site you posted, you'll find:
To attach a file in a "File" field
(i.e. the field type supplied by
FileField module) you have to add a
"description" item to the field array,
like this:
$node->field_file = array(
array(
'fid' => 'upload',
'title' => basename($file_temp),
'filename' => basename($file_temp),
'filepath' => $file_temp,
'filesize' => filesize($file_temp),
'list' => 1, // always list
'filemime' => mimedetect_mime($file_temp),
'description' => basename($file_temp),// <-- add this
), );
maybe that works. You could also try to begin the assignment that way:
$node->field_file = array(0 => array(...
If you are just grabbing content wich has images in, why not just in the body of your nodes change the path of the images to absolute rather than local, then you won't have to worry about CCK at all.
Two other things that you may need to do
"fid" => 'upload', change this to the fid of the file when you save it. If it isn't in the files table then that is something you will need to fix. I think you will need feild_file_save_file()
2.you may need an array "data" under your imageNode array with "title", "description" and "alt" as fields.
To build file information, if you have filefield module, you can also use field_file_load() or field_file_save_file(). See file filefield/field_file.inc for details.
Example:
$node->field_name[] = field_file_load('sites/default/files/filename.gif');