S3 Multipart Upload with SSE-KMS - encryption

I am trying to write a utility using aws-java-sdk (1.11.230).
I am able to write a file with SSE-KMS by using PutObjectRequest as follow:
PutObjectRequest putRequest = new PutObjectRequest(existingBucketName, keyName, file)
.withSSEAwsKeyManagementParams(kmsKeyId);
but while trying to upload it in multipart, I could not find any way to specify encryption configuration for SSE-KMS.
Could anyone please suggest a way to go through this successfully.
Any suggestion will be appreciated.
Vikash Pareek

Can also be done like this:
InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest("example-bucket", "textfile.txt"); SSEAwsKeyManagementParams kms = new SSEAwsKeyManagementParams("KMS-key-alias");
initRequest.setSSEAwsKeyManagementParams(kms);
initResponse = s3Client.initiateMultipartUpload(initRequest);

Finally, I am able to find the solution for this. It can be done by setting headers to InitiateMultipartUploadRequest object as follow:
InitiateMultipartUploadRequest initRequest = new
InitiateMultipartUploadRequest(bucketName, keyName);
initRequest.putCustomRequestHeader("x-amz-server-side-encryption", "aws:kms");
initRequest.putCustomRequestHeader("x-amz-server-side-encryption-aws-kms-key-id", kmsKey);

Related

Flex URLRequest

I have some code written by another person. It's uploading a file to a server. I want to post simillar request but without sending a file (my version will copy file of a given name). I can't use method file.Upload(...). So what function I can use?
This is a code of request with file:
var request:URLRequest = new URLRequest(ApiConfig.ApiUrl);
request.method = URLRequestMethod.POST;
request.data = params;
try
{
_fileRef.upload(request);
}
catch(error:Error)
{
Alert.show(error.message);
}
I simply whant to make simillar request, but without uploading file and not using file instance.
I think it's pretty much dumb question but I don't know how to do this.

Deleting file after upload

I am trying to upload a file with the FileUpload control. When file is uploaded, I extract information from it and then i want to delete it.
I manage to upload it, save it and get the info from it, but when i try to delete it i get the follwing exception
"The process cannot access the file 'D:\IIS**OMITTED***\V75 personal ny.csv' because it is being used by another process.
string fn = Path.GetFileName(fu.PostedFile.FileName);
string SaveLocation = Server.MapPath("UploadedCSVFiles") + "\\" + fn;
FileInfo fi = new FileInfo(SaveLocation);
fu.PostedFile.SaveAs(SaveLocation);
fu.PostedFile.InputStream.Dispose();
DataTable dt = AMethodThatUsesFile(SaveLocation);
fi.Delete();
Try this code to delete file.
System.IO.File.Delete(SaveLocation );
You specified a method AMethodThatUsesFile(SaveLocation);. If it uses any classes like StreamReader to read file, please close the reader using StreamReader.Close(); method before trying to delete
dispose the fi before deleting. and then us File.Delete(). remember to use using statements when use disposable objects, or dispose it after use.
using System.io
File.Delete(Server.MapPath("../Nurturing/" + fnevents));
FileInfo fInfoEvent;
fInfoEvent = new FileInfo(fnevents);
fInfoEvent.Delete();
here fnevents is the name of the file that u are deleting. Nurturing is the name of the folder.

Is it possible to load a local file without having to ask the user to browse to it first in an AIR Application?

I'm writing a small application for myself and instead of using a database I'd like to just use Excel to store the small amount of data I have on my local file system. I want to be able to load that data without having to use the typical FileReference browse() method as it would just be annoying to do every time I use the application.
The code below seems to find the file fine as the file.exists method below and most of the other attributes seem to be correct but the file.data is always null.
I'm guessing this is a security issue and that's why I'm running into this problem but I thought I'd ask and see if there is in fact a way around this problem.
var file:File = new File(fullPath + "\\" + currentFolder + ".txt");
if(file.exists) {
var byteArray:ByteArray = file.data;
}
If you want to read the content of a file, use the following code:
var stream:FileStream = new FileStream();
stream.open("some path here", FileMode.READ);
var fileData:String = stream.readUTFBytes(stream.bytesAvailable);
trace(fileData);
The data property is inherited from FileReference class and it will be populated only after a load call (see this link).
You're close, you just need to combine that with a FileStream object
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var str:String = fileStream.readMultiByte(file.size, File.systemCharset);
trace(str);
more info here

read web.config from another assembly using t4

Does anyone have a good example or helper class that would allow me to read the connection string in a web application from a T4 template residing in ANOTHER assembly referenced by the web application. I am generating some code from the database that it references and i would appresiate some help on how to get the connection string for this use.
ive read George Js example here however it only works when the template resides in the web app, please help!!!
var path = Host.ResolvePath(#"../Web.config");
var map = new ExeConfigurationFileMap { ExeConfigFilename = path };
var config = ConfigurationManager.OpenMappedExeConfiguration(
map,ConfigurationUserLevel.None);
var appSettings = config.AppSettings;
var connectionStrings = config.ConnectionStrings.ConnectionStrings;
You could try to do something like that:
var config = ConfigurationManager.OpenExeConfiguration("../somePathTo/web.config")
// use the config to get values like: config.AppSettings
after a bit of searching around ive found my answer in t4 one may use
path = Host.ResolvePath(relativeFileName)

how to download files to a default dir without poping an option window in Flex/Air?

I'm writing a app with Flex/air,and i need a function that downloading files to the default dir without a pop-up window.i tried to use ftp instead of http but found it's not supported by air.how can i solve this problem?
This should be possible in AIR. I don't know if there's a direct API approach, but you should be able to load the bytes into memory and then flush them into a file. In pseudo-pseudo-code using File and FileStream:
// get the bytes
var loader:URLLoader = new URLLoader();
loader.load("http://www.stackoverflow.com");
...
var bytes:ByteArray = loader.data;
// get the file in the correct location
var f:File = File.documentsDirectory.resolvePath("myfile.txt");
// write the file
var fs:FileStream = new FileStream(f, FileMode.WRITE);
fs.writeBytes(bytes);
fs.close();
There are a few examples out there to look at.
None of this is possible in Flash Player because of the security limits #viatropos suggests.
I don't think you can do that as it's a Security violation. The user must be prompted with a download window so they can choose the directory. I think the thinking goes "if you don't prompt the user, then a Flash/Flex app could download a bunch of junk to their computer without their permission", and that would make adobe look bad :/. I wish you could though.
You can, however, download it using a server side script without asking the user for permission. I do that with ruby to accomplish what you're describing.
Hope that helps,
Lance
You can but only air version because you have to use FileStream
var ff:File = File.desktopDirectory.resolvePath("sample.dwg");
var u:String = obj_l.d1.selectedItem.data + "" + obj_l.d2.selectedItem.label;
var ll3:URLLoader = new URLLoader ();
u = GETURL() + u;
rr.url = u;
//ff.download(rr);
ll3.dataFormat = URLLoaderDataFormat.BINARY;
ll3.load(rr);
ll3.addEventListener(Event.COMPLETE , function (e:Event):void {
var stream:FileStream = new FileStream ();
stream.open(ff,FileMode.WRITE);
stream.writeBytes(ll3.data);
});

Resources