I'm trying to upload a photo to facebook and I can't find seem to get the multipart upload working. I can't find any documentation or libraries that do this. Has anyone else had any luck with this?
Check out the restler library for this instead. I've used it for this exact purpose, and it works great.
Here is some modified code from their examples to show how a file POST would go.
// multipart request sending a file and using https
rest.post('https://twaud.io/api/v1/upload.json', {
multipart: true,
data: {
'sound[message]': 'hello from restler!',
'sound[file]': rest.file('doug-e-fresh_the-show.mp3', null, null, null, 'audio/mpeg')
}
}).on('complete', function(data) {
sys.puts(data.audio_url);
});
Related
I am getting lost with Outlook addin development and really need some help.
I have developed an addin that sends selected email to another server via REST API and it worked fine, but there was a limitation to 1MB so I tried to develop a solution that use ewsURL + SOAP but faced with CORS issues.
Now I got a suggestion to use GRAPH approach (fine with me) but I have no idea how that suppose to work using JavaScript.
Basically I need to get an email as MIME/EML format.
I was guided to check this article: https://learn.microsoft.com/en-us/graph/outlook-get-mime-message
There is endpoint that looks promissing:
https://graph.microsoft.com/v1.0/me/messages/4aade2547798441eab5188a7a2436bc1/$value
But I do not see explanation
how to make authorization process?
I have tried to get token from getCallbackTokenAsync but that did not work
I have tried Office.context.auth.getAccessTokenAsync but getting an issue:
Error code: 13000 Error name: API Not Supported.
Error message: The identity API is not supported for this add-in.
how to get email id
I have tried to do Office.context.mailbox.item.itemId but it looks different compare to what I have seen in the examples (but hopefully that is not a problem)
Please help :-)
There are 2 solutions here. It is preferred longer term to use graph end point with https://learn.microsoft.com/en-us/office/dev/add-ins/develop/authorize-to-microsoft-graph and you can use https://graph.microsoft.com/v1.0/me/messages/4aade2547798441eab5188a7a2436bc1/$value. However this solution requires a backend / service . Transferring through backend is preferable for large content so the content can transfer directly from Exchange to the service.
Alternatively, you can get token from getCallbackTokenAsync, from this doc: https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/use-rest-api
As you noted is that you will need to translate the ews id using convertToRestId. Putting together, your solution should look something like this:
Office.context.mailbox.getCallbackTokenAsync({isRest: true}, function(result){
if (result.status === "succeeded") {
let token = result.value;
var ewsItemId = Office.context.mailbox.item.itemId;
const itemId = Office.context.mailbox.convertToRestId(
ewsItemId,
Office.MailboxEnums.RestVersion.v2_0);
// Request the message's attachment info
var getMessageUrl = Office.context.mailbox.restUrl +
'/v2.0/me/messages/' + itemId + '/$value';
var xhr = new XMLHttpRequest();
xhr.open('GET', getMessageUrl);
xhr.setRequestHeader("Authorization", "Bearer " + token);
xhr.onload = function (e) {
console.log(this.response);
}
xhr.onerror = function (e) {
console.log("error occurred");
}
xhr.send();
}
});
I'm trying to send attachment file from youtrack to another system (in this example to trello) without the use of image url but its content
I cannot send it as image url in youtrack because my system is closed and accessible to only those that have vpn.
Problem is with reading inputStream from content of attachement in workflow. I symply have no idea how to do it and youtrack documentation havent touched it (as far as my research goes)
Code: (with truncated not important parts)
//...
exports.rule = entities.Issue.onChange({
//...
action: function(ctx) {
//...
var link = '/1/cards/' + issue['trelloIssueId'] + '/attachments';
issue.comments.added.forEach(function(comment) {
comment.attachments.forEach(function(attachment) {
var response = connection.postSync(link, {
name: attachment.name,
file: attachment.content,
mimeType: attachment.mimeType
});
//...
});
});
},
requirements: {}
});
from this I got error:
TypeError: invokeMember (forEach) on jetbrains.youtrack.workflow.sandbox.InputStreamWrapper#677a561f failed due to: Unknown identifier: forEach
How do I have to prepare content to ba abble to send it with postSync method?
It looks like you tried to iterate over issue.comments.added while the loop should be executed over issue.comments as there is no added key for an issue's comments Set as per the following documentation page suggest: https://www.jetbrains.com/help/youtrack/devportal/v1-Issue.html
Please let me know if that works.
I need to upload files in Aurelia Js. I don't know how to send file to server(hit to given API). I have two doubts, one is in my 'content-type' and another one is, do i need to change my image object to any other format. Here is the code i used,
scanupload.html :
<input type="file" files.bind="selectedFiles" change.delegate="onSelectFile($event)">
scanupload.js :
onSelectFile($event){ var myurl = 'http://cdn.dmiapp.tk/file?authToken=bLNYMtfbHntfloXBuGlSzPueilaHtZx&type=jpg&name=testfile.jpg&organizationId=1&userId=7&sourceType=USER_UPLOADS';
this.httpValueConverter.call_http(myurl,'POST',{file :this.selectedFiles[0]},'fileupload')
.then(data => {
console.log(data);
if(data.meta && data.meta.statusCode == 200) {
console.log('success');
}
});}
httpservice.js :
call_http(url,method,myPostData,action,params) {
return this.httpClient.fetch(url,
{
method: method,
body : myPostData,
headers : {
'authorization': this.authorization,
'Content-Type':'form-data'
}
})
.then(response => response.json());}
Error : bad request and unsupported media file.
Also tried content type, form-data and multipart/form-data
If it's an image your media type must be: "image/jpeg" and you can try to upload the image as a blob.
This does not seem to be an Aurelia-specific issue.
Try first to make a simple example working such as:
Upload image using javascript
When this works refactor it to an Aurelia view.
Also, verify that you have indeed configured your server to support the necessary mime type.
For multipart/form-data you can look at the following tweaks and packages:
https://github.com/expressjs/node-multiparty
https://github.com/expressjs/multer
Are there ANY code examples of how to use Google Cloud Print (using the new OAuth 2) and how when a document comes into the Google Cloud Print queue to automatically print it?
Pretty much what I am trying to do is not spend thousands of dollars that when an order is submitted to our online store, that the order automatically gets printed to our printer. Any ideas, pointers, code examples.
I have done a bunch of searching, and a lot of examples using C#, use Google's old service, not the OAuth2, documentation.
Pretty much, I need a service that will sent a print command to our printer when we get an order in. I can write the part from the store to the service, it is the service to the printer part I have a ton of trouble with.
Thanks in advance.
There's a brilliant PHP class you can download and use that does exactly that:
https://github.com/yasirsiddiqui/php-google-cloud-print
The problem with what you want to achieve is that Google Cloud Print is meant for authenticated users submitting their own print jobs. If I understand correctly, you want to have the server submit a print job as a callback after receiving an order. Therefore, print jobs need to be submitted by a service account, not a Google user. This can be done (we use it in production at the company I work for) using a little hack, described here:
Share printer with Google API Service Account
I can't help you with C# or PHP code, basically you need to be able to make JWT authenticated calls to Google Cloud Print, here you are a code snippet in NodeJS, hope it helps:
var request = require('google-oauth-jwt').requestWithJWT();
service.submitJob = function(readStream,callback) {
// Build multipart form data
var formData = {
printerid: cloudPrintConfig.googleId,
title: 'My Title',
content: readStream,
contentType: "application/pdf",
tag: 'My tag',
'ticket[version]': '1.0',
'ticket[print]': ''
};
// Submit POST request
request({
uri: cloudPrintConfig.endpoints.submit,
json: true,
method: 'post',
formData: formData,
jwt: cloudPrintConfig.jwt
}, function (err, res, body) {
if (err) {
callback(err,null);
} else {
if (body.success == false) {
callback('unsuccessful submission',null);
} else {
callback(null, body);
}
}
});
}
Details about JWT credentials can be found here
Im uplaoding file to Amazon S3 using dojo.io.iframe.send:
var d = dojo.io.iframe.send ({
url: url,
contentType: "multipart/form-data",
method: "POST",
form: this._form.domNode,
handleAs: "text",
load: dojo.hitch(this, function (respText) {
alert(1)
this.showLoading(false);
this.onSuccess(this.nodeFormName.value);
}),
error: dojo.hitch(this, function (err) {
console.log("err", err)
this.showError(err);
})
}, true);
I can see via using sniffer that file upload finished (and file is indeed in S3 bucket) but "load" or "error" callback functions are never called. Via sniffer I can see that response code is 204 "no content" and I assume that it may be root of the problem. Anyone had similar problem or know how to solve it?
Found solution. Since the only way for iframe to process result is to get format, I added redirect header for successfull upload on Amazon S3. Redirecting now to static page in format success
Did the trick.