I have a requirement to store attachment on CouchDB. How will I do it using Java. What APIs I can use? Is there any sample code or documentation I can refer? Currently we are using cloudantdb, but we planing to use CouchDB on Azure
com.cloudant.client.api.Database;
com.cloudant.client.api.model.Response;
Thanks
If you use LightCouch Java API
InputStream in = // .. init stream
// save under a new document, a generated UUID is assigned as id.
Response response = dbClient.saveAttachment(in, "photo.png", "image/png");
// save to an existing document
dbClient.saveAttachment(in, "file.pdf", "application/pdf", "doc-id", "doc-rev");
// save under a new document with the given id.
dbClient.saveAttachment(in, "photo.jpeg", "image/jpeg", "doc-id", null);
// get attachment
InputStream in = dbClient.find("doc-id/photo.jpeg");
// ..
in.close(); // close the stream
Related
This link (https://developers.docusign.com/docs/esign-rest-api/how-to/download-envelope-documents/) mentions how I can download separate documents using their document IDs. Also found a way to download the documents as a zip file. But is there a way to download them as a combined PDF using the API?
Thanks.
Not sure what lang you're using but C# code will be this (note "combined" option).
For other langs - check my blog post
// You would need to obtain an accessToken using your chosen auth flow
var apiClient = new ApiClient(basePath);
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
var envelopesApi = new EnvelopesApi(apiClient);
string accountId; // accountId for your DocuSign account
string envelopeId; // envelopeId that you are working on
// produce a ZIP file with all documents including the CoC
Stream results1 = envelopesApi.GetDocument(accountId, envelopeId, "archive");
// produce a PDF combining all signed documents as well as the CoC
Stream results2 = envelopesApi.GetDocument(accountId, envelopeId, "combined");
// produce a particular document with documentId "1"
Stream results3 = envelopesApi.GetDocument(accountId, envelopeId, "1");
//TODO - use Stream to write or send the file for your use
Im working on a bot with Bot framework v4 in nodejs.
I want my Conversation reference for every user to be stored into an azure db.
Conversation reference is in a nested dictionary format. {'convid':{"a":'value","b":"value"}}
I want this dictionary to be stored in Azure DB (Which Db would be suitable?free version?Paid?) so that i could later retrieve this DB and send out a proactive messages to all users whose conv ref is stored.
I just want to know how to store dictionary into any azure DB with node js?
and retrieve it later? Any help would be appreciated.
Saving the conversation reference during a (private) conversation can be achieved using the following snippet.
conversationReference = TurnContext.getConversationReference(context.activity);
You can eventually save this JSON directly to CosmosDB using the Cosmos Javascript SDK.
const databaseDefinition = { id: "sample database" };
const collectionDefinition = { id: "sample collection" };
const { database } = await client.databases.create(databaseDefinition);
const { container } = await database.containers.create(collectionDefinition);
const { resource } = await container.items.create(conversationReference);
#Sree - You can pull all the conversation using Graph API's please check the documents. If you have requirement to store data in dictionary only, you can explore Cosmos db.
Please check Pricing.
I have to log the user-bot conversation in CosmosDB for audit/history purpose. In V3 using .Net, I was using table logger module, like the below code.
builder.RegisterModule(new TableLoggerModule(account, chatHistoryTableName));
Now we are upgrading/rewriting the bot to V4 in NodeJS. Please guide if there is a similar approach available for V4 in NodeJS to save the entire conversation?
This example hasn't been merged yet: https://github.com/Microsoft/BotBuilder-Samples/pull/1266
It uses AzureBlobTranscriptStore and TranscriptLoggerMiddleware
const { AzureBlobTranscriptStore } = require('botbuilder-azure');
const { TranscriptLoggerMiddleware } = require('botbuilder-core');
// Get blob service configuration as defined in .bot file
const blobStorageConfig = botConfig.findServiceByNameOrId(BLOB_CONFIGURATION);
// The transcript store has methods for saving and retrieving bot conversation transcripts.
let transcriptStore = new AzureBlobTranscriptStore({storageAccountOrConnectionString: blobStorageConfig.connectionString,
containerName: blobStorageConfig.container
});
// Create the middleware layer responsible for logging incoming and outgoing activities
// into the transcript store.
var transcriptMiddleware = new TranscriptLoggerMiddleware(transcriptStore);
adapter.use(transcriptMiddleware);
This should provide a good start.
https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-howto-v4-state?view=azure-bot-service-4.0&tabs=javascript
While debugging my Connect listener (REST, Java), I am trying to create a PDF document based on xml in the Connect log for Demo. (I have to emulate Docusign POST request while security issues are being resolved.)
I have DocuSign Connect Service activated with “Include Documents” and "Include Certificate of Completion" checked.
I can see Attachment element in the log’s xml but not DocumentPDF element. When saving content as a byte array into PDF file and then trying to open it, it cannot be opened in Acrobat.
Is Attachment element in the Connect Log supposed to be a PDF document?
Here is my code to convert to pdf file:
String documentName = parseXMLDoc(xmlDoc, "DocumentStatus[1]/Name");
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd HHmmsss");
String nowTime = fmt.format(new Date());
OutputStream out = new FileOutputStream("c:\\temp\\"+documentName.replaceAll(".pdf","_"+nowTime+".pdf"));
BASE64Decoder decoder = new BASE64Decoder();
String encodedBytes = parseXMLDoc(xmlDoc, "Attachment/Data");
byte[] decodedBytes = decoder.decodeBuffer(encodedBytes);
out.write(decodedBytes);
out.close();
where parseXMLDoc is
public static String parseXMLDoc(Document xmlDoc, String searchToken) {
String xPathExpression;
try {
XPath xPath = XPathFactory.newInstance().newXPath();
xPathExpression = "//" + searchToken;
return (xPath.evaluate(xPathExpression, xmlDoc));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
No the Connect log does NOT contain the actual document bytes... the documents are only included in the actual Connect pushes to your external listener. The log files simply contain metadata around the transaction, not the actual content.
You can possibly get a full response from DocuSign by using https://Webhook.site where you will be given a temporary URL for listening. Plug the temporary URL into the DocuSign Connection (create a new connection for testing), and open the XML packet from the dashboard on the webhook site dashboard when it arrives from DocuSign.
I am using sharepoint 2010 enterprise edition. I have activated Document ID service which will generate a doc Id for each doc when you upload. when i am first time uploading or saving the document it has no issues. It is getting saved. The issue i am facing is when i open the uploaded document and edit or update it and while saving it again it is giving the webexception "Underlying connection got disconnected. Connection closed prematurely".
I also tried to debug and found the response did not have header.
We were trying to perform in a windows application to edit and save the document.
we are trying to save the document by creating a webrequest.
please provide your idea on this issue.
please see the code below.
"
WebUrl webUrl = UrlToWebUrl(destinationUri);
System.Collections.Specialized.NameValueCollection methodData = new System.Collections.Specialized.NameValueCollection();
// Add general request to stream
methodData.Add("method","put document:" + GetServerExtensionsVersion(webUrl.SiteUrl));
methodData.Add("service_name","");
methodData.Add("put_option","overwrite,createdir,migrationsemantics");
methodData.Add("keep_checked_out","false");
HttpWebRequest req = StartWebRequest(GetAuthorURL(webUrl.SiteUrl), methodData);
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;
System.IO.Stream reqStream = req.GetRequestStream();
RemoveSourceControlProperties(properties);
WriteDocumentData(reqStream, webUrl.FileUrl, file, properties);
reqStream.Flush();
reqStream.Close();
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
try
{
if (!PutDocumentResponseSuccess(GetResponseString(response)))
{
throw new FrontPageRPCException("Failed to save document.", destinationUri);
}
}
finally
{
if (null != response) response.Close();
}
}
"