Can someone please help me in uploading file in Podio? I am new in Podio library so I am trying but getting lots of errors.
Warning: realpath() expects parameter 1 to be a valid path, resource given in /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php on line 54
Warning: filesize() expects parameter 1 to be a valid path, resource given in /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php on line 54
Fatal error: Uncaught PodioBadRequestError: "'source' parameter must given as multipart/form-data with type 'file'"
Request URL: http://api.podio.com/file/v2/
Stack Trace: #0 /home/gphxyz/public_html/decode/podio-php/lib/Podio.php(352): Podio::request('POST', '/file/v2/', Array, Array)
#1 /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php(54): Podio::post('/file/v2/', Array, Array)
#2 /home/gphxyz/public_html/decode/podio-php/index.php(22): PodioFile::upload(Resource id #72, 'http://geeksper...')
#3 {main} thrown in /home/gphxyz/public_html/decode/podio-php/lib/Podio.php on line 289
My code is below:
<?php
require_once 'PodioAPI.php';
//Initalize Podio connection
$client_id = '';
$client_secret = "";
Podio::setup($client_id, $client_secret);
//App ID's
$opname_app_id = '21209880';
$opname_app_token = "";
Podio::authenticate_with_app($opname_app_id, $opname_app_token);
$opname_auth = Podio::$oauth;
$filepath = 'http://geeksperhour.xyz/decode/podio-php/credit.jpg';
$filename = 'credit.jpg';
$goFile = PodioFile::upload($filepath, $filename);
$fileID = $goFile->file_id;
print_r($fileID);
You might find that lib/podio.php for file uploads is deprecated since a while.
See the open Ticket on Github: The usage of the #filename API for file uploading is deprecated - File upload #74
Changing the API in line 189 will allow you to follow the documentation again.
from
if (!empty($options['upload'])) {
curl_setopt(self::$ch, CURLOPT_POST, TRUE);
curl_setopt(self::$ch, CURLOPT_SAFE_UPLOAD, FALSE);
curl_setopt(self::$ch, CURLOPT_POSTFIELDS, $attributes);
self::$headers['Content-type'] = 'multipart/form-data';
}
to
if (!empty($options['upload'])) {
$cfile = curl_file_create(substr($attributes[ "source" ], 1));
// Assign POST data
$attributes[ "source" ] = $cfile;
curl_setopt(self::$ch, CURLOPT_POST, TRUE);
curl_setopt(self::$ch, CURLOPT_POSTFIELDS, $attributes);
self::$headers['Content-type'] = 'multipart/form-data';
}
Worked for me in a PHP 7.2 Ubuntu 16.04 environment.
Also make sure the path to your file is pointing to local a path of your server.
Additional if you use composer you might find it useful to point to the master rather than the latest release:
composer require podio/podio-php:dev-master
As error message says: expects parameter 1 to be a valid path, resource given in /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php on line 54
So, please provide valid local file path instead of $filepath = 'http://geeksperhour.xyz/decode/podio-php/credit.jpg';
Related
I created an API function to work with S3. I imported the template swagger. After deployment, I tested with a Node.js project by the npm module aws-api-gateway-client.
It works well with: get bucket lists, get bucket info, get one item, put a bucket, put a plain text object, however I am blocked with put a binary file.
firstly, I ensure ACL is allowed with all permissions on S3. secondly, binary support also added
image/gif
application/octet-stream
The code snippet is as below. The behaviors are:
1) after invokeAPI, the callback function is never hit, after sometime, the Node.js project did not respond. no any error message. The file size (such as an image) is very small.
2) with only two times, the uploading seemed to work, but the result file size is bigger (around 2M bigger) than the original file, so the file is corrupt.
Could you help me out? Thank you!
var filepathname = './items/';
var filename = 'image1.png';
fs.stat(filepathname+filename, function (err, stats) {
var fileSize = stats.size ;
fs.readFile(filepathname+filename,'binary',function(err,data){
var len = data.length;
console.log('file len' + len);
var pathTemplate = '/my-test-bucket/' +filename ;
var method = 'PUT';
var params = {
folder: '',
item:''
};
var additionalParams = {
headers: {
'Content-Type': 'application/octet-stream',
//'Content-Type': 'image/gif',
'Content-Length': len
}
};
var result1 = apigClient.invokeApi(params,pathTemplate,method,additionalParams,data)
.then(function(result){
//never hit :(
console.log(result);
}).catch( function(result){
//never hit :(
console.log(result);
});;
});
});
We encountered the same problem. API Gateway is meant for limited data (10MB as of now), limits shown here,
http://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
Self Signed URL to S3:
Create an S3 self signed URL for POST from the lambda or the endpoint where you are trying to post.
How do I put object to amazon s3 using presigned url?
Now POST the image directly to S3.
Presigned POST:
Apart from posting the image if you want to post additional properties, you can post it in multi-form format as well.
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#createPresignedPost-property
If you want to process the file after delivering to S3, you can create a trigger from S3 upon creation and process with your Lambda or anypoint that need to process.
Hope it helps.
I think my code was working previously with this same code
var streamProvider = new CustomMultipartFormDataStreamProvider(path);
// Upload media
await Request.Content.ReadAsMultipartAsync(streamProvider);
but now it gives System.InvalidOperationException error:
Access to the path 'C:\xxx\Projects\Test Projects\CL.MiClaim\CL.MiClaim\uploads' is denied.
When I provide a file for upload then it works al right. This below doesn't work (since it hasn't yet read the request content yet??)
if (streamProvider.FileData.Count > 0)
{
}
any help will be appreciated.
Note: example code can be found at:
http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2
I have set up magento locally in my system using XAMPP
I have created a file in root directory named dm.php with the contents
<?php
/**
* Example of products list retrieve using Customer account via Magento REST API. OAuth authorization is used
*/
$callbackUrl = "http://localhost/dm.php";
$temporaryCredentialsRequestUrl = "http://localhost/mage2/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://localhost/mage2/oauth/authorize';
$accessTokenRequestUrl = 'http://localhost/mage2/oauth/token';
$apiUrl = 'http://localhost/mage2/api/rest';
$consumerKey = 'enhksf7u33p3snubewb6zcq0z9c63bvv';
$consumerSecret = 'p7e835cdcxofokeep749jgzz4l1e306p';
session_start();
if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
$_SESSION['state'] = 0;
}
try {
$authType = ($_SESSION['state'] == 2) ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
$oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
$oauthClient->enableDebug();
if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
$requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
$_SESSION['secret'] = $requestToken['oauth_token_secret'];
$_SESSION['state'] = 1;
header('Location: ' . $adminAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token']);
exit;
} else if ($_SESSION['state'] == 1) {
$oauthClient->setToken($_GET['oauth_token'], $_SESSION['secret']);
$accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl);
$_SESSION['state'] = 2;
$_SESSION['token'] = $accessToken['oauth_token'];
$_SESSION['secret'] = $accessToken['oauth_token_secret'];
header('Location: ' . $callbackUrl);
exit;
} else {
$oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
$resourceUrl = "$apiUrl/products";
$oauthClient->fetch($resourceUrl);
$productsList = json_decode($oauthClient->getLastResponse());
print_r($productsList);
}
} catch (OAuthException $e) {
print_r($e);
}
But this is giving me the following error
Fatal error: Class 'OAuth' not found in D:\Webserver\xampp\htdocs\dm.php on line 19
Can anybody shed some light on this
Thanks
Since oauth is not possible to install in xampp windows i changed the contents of my dm.php file to this.
<?php
$ch = curl_init('http://localhost/mage2/api/rest/customers');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$customers = curl_exec($ch);
echo $customers;
?>
Now i am getting an error like this
{"messages":{"error":[{"code":403,"message":"Access denied"}]}}
What am i doing wrong?
First of all
Go to magento admin panel System->Webservice->RESt Roles->Guest->Resources Access ->SET ALL
Similarly Go to System->Webservice->RESt Attribute->Guest->Resources Access ->SET ALL
Then Hit this url http://****/chanchal/magento/api/rest/products in web Browser and check what error it shows....
According to me it must show product in your website in xml format.
Please let me know..
EDIT:
I configured a localhost just now and got this output refer the Screenshot. Be sure there is product in your magento.
Similarly follow the above steps for admin,customer then create a Ouath consumer from admin panel , Install RESTClient For Mozilla Firefox And follow Here
These for steps are necessary for the setup..the link might help you..
Authentication Endpoints
1./oauth/initiate - this endpoint is used for retrieving the Request Token.
2./oauth/authorize - this endpoint is used for user authorization (Customer).
3./admin/oauth_authorize - this endpoint is used for user authorization (Admin).
4./oauth/token - this endpoint is used for retrieving the Access Token.
Let me know if you have any issues.
Best of luck
A bit of code modifications will easily solve this error 403 forbidden.
What magento engine does is that it uses the default guest user to provide access to the REST api methods. The guest user does not have much powers so it should be better to change this functionality of magento. There are 2 ways of doing this:
1) Quick and dirty fix: in the file /app/code/core/Mage/Api2/Model/Auth.php, change the value of: DEFAULT_USER_TYPE = 'guest' to DEFAULT_USER_TYPE = 'admin'. In the file /app/code/core/Mage/Api2/Model/Auth/Adapter.php, change this line from return (object) array('type' => Mage_Api2_Model_Auth::DEFAULT_USER_TYPE, 'id' => null); to this:
return (object) array('type' => Mage_Api2_Model_Auth::DEFAULT_USER_TYPE, 'id' => '1');
This way the authentication system will not be broken.
2) Proper and long run fix: Override the two functionalities using the magento overriding mechanism to have a better solution in accordance to magento standards. This way the core files will be intact.
We use this link to install oauth for php. Its good and easy to add extension for php.
install oauth php
I hope it helps to all and would solved 'OAuth' not found fatal error.
I had the same issue and was struggling for a week but just try insatlling new version of xammp or wamp with supports ouath.The better solution was ,I installed Ammps 1.9 and in php5.4 I resolved the extension of oauth but still make sure that you select the proper php for extension oauth is supported (php5.4)
For installing Oauth : http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html
Installing PHP Extension for Oauth :
1. Download php_oauth.dll file and add it under C:\xampp\php\ext\
2. add [PHP_OAUTH] extension=php_oauth.dll in php.ini
Im using 000webhost as a way to host my portfolio of websites. However Im getting this error thrown in which doesn't happen to me on localhost.
Notice (8): Undefined index: Upload [APP/Controller/UploadsController.php, line 32]
This is the code it seems to be referring to,
public function add() {
$this->render();
if($this->request->is('post')){
$file = $this->request->data['Upload']['file'];
if($this->Upload->save($this->data) && move_uploaded_file($file['tmp_name'],APP.'webroot/files/uploads'.DS.$this->Upload->id.'.mp4'))
{
$this->Session->setFlash('<p class="uploadflash">The upload has been saved</p>', true);
$this->redirect(array('controller'=>'Uploads', 'action' => 'watch', $this->Upload->id));
} else {
$this->Session->setFlash('<p class="loginerror">The upload could not be saved, mp4 files can be saved only.</p>', true);
}
}
}
Any ideas as to why this is happening?
Also in addition my Elements are not showing up on this online hosting either?
I get thrown this error on the page
Element Not Found: Elements/uploads/recentuploads.ctp
Does anyone else seem to have this problem??
Upon further inspection I have found that the server does not allow file upload sizes to exceed 2mb, in this instance PHP throws the error above.
When trying to upload files to rackspace cloudfiles, I am getting this error.
I tried to trace the source of error and I assume that it is coming from this line of code:
$container = $conn->get_container('test');
This is the complete error that I am getting:
Notice
Undefined offset: 8
File: /dm/cloudfiles/cloudfiles.php, Line: 1588
And this is the code for upload:
<?php
// include the Cloud API.
require('cloudfiles/cloudfiles.php');
// Rackspace Connection Details;
// cloud info
$username = "tariehk"; // username
$key = ""; // api key
// Connect to Rackspace
$auth = new CF_Authentication($username, $key);
$auth->authenticate();
$conn = new CF_Connection($auth);
//Set the Container you want to use
$container = $conn->get_container('dm');
//Temp store the file
$localfile = $_FILES['uploadfile']['tmp_name'];
$filename = $_FILES['uploadfile']['name'];
//exit();
//Uploading to Rackspace Cloud
$object = $container->create_object($filename);
$object->load_from_filename($localfile);
echo "Your file has been uploaded";
?>
This problem has been fixed in their repo but it still exists in the download version.
The fixes can be found here
https://github.com/towynlin/php-cloudfiles/commit/02a8c658db7e9969b35bb57c47ede232521a6617
and
https://github.com/towynlin/php-cloudfiles/commit/78c5d612fb5a7037e92f61acfaf10b59e09239e8
bug report is here
https://github.com/rackspace/php-cloudfiles/pull/23
Its just a few lines, I just patched it myself.