Uploading to cloud storage with API, RequestException - google-cloud-storage

Can anyone tell me why this code gets a request exception?
Google.Apis.Storage.v1.Data.Object obj = new Google.Apis.Storage.v1.Data.Object();
obj.Bucket = "testbucket1817";
obj.ContentType = "binary/octet-stream";
obj.SelfLink = #"C:\Users\User\Desktop\file";
obj.Name = "filename";
Google.Apis.Storage.v1.ObjectsResource.InsertRequest uploadrequest = new ObjectsResource.InsertRequest(storagecredentials, obj, "testbucket1817");
uploadrequest.Execute();
When run I get this error message-
Required [400]
Errors [
Message[Required] Location[ - ] Reason[required] Domain[global]
Message[Required] Location[ - ] Reason[required] Domain[global]
]
I'm not sure about the selflink thing or the content type (for an xml file) but there's nothing anywhere that actually says how this should be done.
Thanks anyone

InsertMediaUpload seems to work fine. Don't know what the difference is from InsertRequest other than I can figure out where to put the data with InsertMediaUpload. So whatever file you want to upload, just set a stream as File.Open(yourfile, FileMode.Open) and set an object like I did in the question.
Google.Apis.Storage.v1.ObjectsResource.InsertMediaUpload uploadmedia = new
ObjectsResource.InsertMediaUpload(ss, object, "bucketname", fileStream, "binary/octet-stream");
that sets up the upload and then uploadmedia.Upload() executes.
Thanks everyone!
Ross

Related

AzureDevOps: Bug Creation with Resolved to Field and Tags Addition

I have a service to create bugs and using the below Documentation
https://learn.microsoft.com/es-es/azure/devops/integrate/quickstarts/create-bug-quickstart?view=azure-devops&viewFallbackFrom=vsts
Question is that,
a. Since service account(say:abc) is creating bug, once bugs gets resolved, its getting assigned to that same service account(abc). Is here a way i can hardcode to assign to someone say:xyz while bug is getting created. Or
Is there any JsonPathOperation Path that i can use to solve this?
b. What is JsonPathOperation Path for adding the tags to the Bug?
Appreciate any help or please direct to any references
Thanks
You can try to add the following code:
a.
patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.AssignedTo",
Value = "***#***.com"//Accound Name
}
);
b.
patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.Tags",
Value = "tag"//Tag Name
}
);

Key value in AWSIoTDataManager

I am working with a project where I don't get it the value of
awsiotdatamanager is static string or it generated from AWS. I found it like this in sample code Also I read code this and this but I am getting more and more confused.
let AWSIoTDataManager = "MyIotDataManager"
let iotDataManager = AWSIoTDataManager(forKey: AWSIoTDataManager)
Thanks in advance :)

How to edit pasted content using the Open XML SDK

I have a custom template in which I'd like to control (as best I can) the types of content that can exist in a document. To that end, I disable controls, and I also intercept pastes to remove some of those content types, e.g. charts. I am aware that this content can also be drag-and-dropped, so I also check for it later, but I'd prefer to stop or warn the user as soon as possible.
I have tried a few strategies:
RTF manipulation
Open XML manipulation
RTF manipulation is so far working fairly well, but I'd really prefer to use Open XML as I expect it to be more useful in the future. I just can't get it working.
Open XML Manipulation
The wonderfully-undocumented (as far as I can tell) "Embed Source" appears to contain a compound document object, which I can use to modify the copied content using the Open XML SDK. But I have been unable to put the modified content back into an object that lets it be pasted correctly.
The modification part seems to work fine. I can see, if I save the modified content to a temporary .docx file, that the changes are being made correctly. It's the return to the clipboard that seems to be giving me trouble.
I have tried assigning just the Embed Source object back to the clipboard (so that the other types such as RTF get wiped out), and in this case nothing at all gets pasted. I've also tried re-assigning the Embed Source object back to the clipboard's data object, so that the remaining data types are still there (but with mismatched content, probably), which results in an empty embedded document getting pasted.
Here's a sample of what I'm doing with Open XML:
using OpenMcdf;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
...
object dataObj = Forms.Clipboard.GetDataObject();
object embedSrcObj = dateObj.GetData("Embed Source");
if (embedSrcObj is Stream)
{
// read it with OpenMCDF
Stream stream = embedSrcObj as Stream;
CompoundFile cf = new CompoundFile(stream);
CFStream cfs = cf.RootStorage.GetStream("package");
byte[] bytes = cfs.GetData();
string savedDoc = Path.GetTempFileName() + ".docx";
File.WriteAllBytes(savedDoc, bytes);
// And then use the OpenXML SDK to read/edit the document:
using (WordprocessingDocument openDoc = WordprocessingDocument.Open(savedDoc, true))
{
OpenXmlElement body = openDoc.MainDocumentPart.RootElement.ChildElements[0];
foreach (OpenXmlElement ele in body.ChildElements)
{
if (ele is Paragraph)
{
Paragraph para = (Paragraph)ele;
if (para.ParagraphProperties != null && para.ParagraphProperties.ParagraphStyleId != null)
{
string styleName = para.ParagraphProperties.ParagraphStyleId.Val;
Run run = para.LastChild as Run; // I know I'm assuming things here but it's sufficient for a test case
run.RunProperties = new RunProperties();
run.RunProperties.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Text("test"));
}
}
// etc.
}
openDoc.MainDocumentPart.Document.Save(); // I think this is redundant in later versions than what I'm using
}
// repackage the document
bytes = File.ReadAllBytes(savedDoc);
cf.RootStorage.Delete("Package");
cfs = cf.RootStorage.AddStream("Package");
cfs.Append(bytes);
MemoryStream ms = new MemoryStream();
cf.Save(ms);
ms.Position = 0;
dataObj.SetData("Embed Source", ms);
// or,
// Clipboard.SetData("Embed Source", ms);
}
Question
What am I doing wrong? Is this just a bad/unworkable approach?

Facebook & Classic ASP - Passing custom parameters to fan page tab - error with no data

We have our app working using this code (Is it possibile to pass parameters to the callback URL of a FB app which is accessed through a tab?), but the issue arises when there is no app_data parameter passed in. Here is an example of what we mean:
Works Fine: ("test" is written out fine)
https://www.facebook.com/phillypours/app_397493550309543?app_data=test
Does NOT Work:
https://www.facebook.com/phillypours/app_397493550309543
Code used with Base64 Encode & JSON Decode:
myArray = Split(Request("signed_request"), ".")
encoded_sig = myArray(0)
payload = myArray(1)
sig = base64_decode(Replace(encoded_sig, "-_", "+/"))
set data = JSON.parse(base64_decode(Replace(payload, "-_", "+/")))
Response.Write data.app_data
This is the error we receive when no parameter is passed in:
Object doesn't support this property or method: 'data.app_data'
Anyone have any thoughts on how to trap for this? I cannot do anything with "data.app_data" since this is what throws the error.
Any help would be greatly appreciated!!!
Thank you.
Dennis
I found a work around for this. Wanted to share to others could benefit. thanks, Dennis
<!--#INCLUDE VIRTUAL="/includes/fb_base64.asp"-->
<!--#INCLUDE VIRTUAL="/includes/fb_json_decode.asp"-->
Function parsePageSignedRequest()
If Request("signed_request") <> "" Then
myArray = Split(Request("signed_request"), ".")
payload = myArray(1)
payload_decoded = base64_decode(payload)
set data = JSON.parse(payload_decoded)
If instr(payload_decoded,"""app_data""") Then
AppData = data.app_data
End If
If instr(payload_decoded,"liked"":true,") Then
LikeStatus = True
End If
End If
End Function

How to get the underlying object from a SpyMessage in JBossMQ

I am trying to write a simple Java program that reads from JBossMQ's jms_messages table using JDBC. I am using JBoss 4.0.4.GA.
I can get the as far as getting a SpyMessage, but how can I get the actual message content (which is an Object in the particular case I'm looking at).
I have a result set "rs" from this statement:
SELECT messageid, messageblob FROM jms_messages WHERE DESTINATION LIKE 'TOPIC.MyTopic%' limit 3"
and then I do this (based on JBoss code):
long messageid = rs.getLong(1);
SpyMessage message = null;
byte[] st = rs.getBytes(2);
ByteArrayInputStream baip = new ByteArrayInputStream(st);
ObjectInputStream ois = new ObjectInputStream(baip);
message = SpyMessage.readMessage(ois);
message.header.messageId = messageid;
String jmstype = message.getJMSType();
String jms_message_id = message.getJMSMessageID();
System.out.println("jmstype=" +jmstype);
System.out.println("jms_message_id=" +jms_message_id);
String propertyName;
Enumeration e = message.getPropertyNames();
while (e.hasMoreElements())
{
propertyName = (String)e.nextElement();
System.out.println("property name = " +propertyName);
}
but I get no properties printed and I don't know how to get my actual object from the SpyMessage (actually a SpyObjectMessage). I'd be grateful for any pointers.
I've tried asking this question on the JBoss forum without reply, so I'm hoping for better luck here.
Thanks.
Sorry - the answer was so obvious I'm not really sure what I was thinking when I posted the question - simply:
Object objMessage = ((SpyObjectMessage)message).getObject();