Hi …
Code provided above is of old library , i am using this https://github.com/storj/storj/wiki/Libuplink-Walkthrough
example for my reference
This is a code i am using for uploading file
func UploadDataToStorj(ctx context.Context,satelliteAddress string, encryptionPassphrase string, apiKey uplink.APIKey,
bucketName, uploadPath string, dataToUpload byte) error {
//ctx = context.Background()
//upl, err := uplink.NewUplink(ctx, nil)
var cfg uplink.Config
cfg.Volatile.TLS.SkipPeerCAWhitelist = true
upl, err := uplink.NewUplink(ctx, &cfg)
if err != nil {
return fmt.Errorf("could not create new Uplink object: %v", err)
}
defer upl.Close()
proj, err := upl.OpenProject(ctx, satelliteAddress, apiKey)
if err != nil {
return fmt.Errorf("could not open project: %v", err)
}
defer proj.Close()
_, err = proj.CreateBucket(ctx, bucketName, nil)
if err != nil {
return fmt.Errorf("could not create bucket: %v", err)
}
fmt.Println("Creating new encryption ",encryptionPassphrase)
encryptionKey, err := proj.SaltedKeyFromPassphrase(ctx, encryptionPassphrase)
if err != nil {
return fmt.Errorf("could not create encryption key: %v", err)
}
access := uplink.NewEncryptionAccessWithDefaultKey(*encryptionKey)
//Getting bucket info
//GetBucketInfo
// fmt.Println(“Getting Bucket info”);
// bucketinfo, err,third :=proj.GetBucketInfo(ctx, bucketName)
// if err != nil{
// return fmt.Errorf(“could not open bucket %q: %v”, bucketName, err)
// }
// fmt.Println(third);
fmt.Println(“Opening created bucket”,bucketName);
// Open up the desired Bucket within the Project
bucket, err := proj.OpenBucket(ctx, bucketName, access)
if err != nil {
return fmt.Errorf(“could not open bucket %q: %v”, bucketName, err)
}
defer bucket.Close()
fmt.Println("Uploading data\n\n");
buf := bytes.NewBuffer(dataToUpload)
err = bucket.UploadObject(ctx, uploadPath, buf, nil)
if err != nil {
return fmt.Errorf("could not upload: %v", err)
}
}
// buf := bytes.NewBuffer(dataToUpload)
// err = bucket.UploadObject(ctx, uploadPath, buf, nil)
// if err != nil {
// return fmt.Errorf("could not upload: %v", err)
// }
fmt.Println("Opening bucket for downloading\n\n");
// Initiate a download of the same object again
readBack, err := bucket.OpenObject(ctx, uploadPath)
if err != nil {
return fmt.Errorf("could not open object at %q: %v", uploadPath, err)
}
defer readBack.Close()
// We want the whole thing, so range from 0 to -1
strm, err := readBack.DownloadRange(ctx, 0, -1)
if err != nil {
return fmt.Errorf("could not initiate download: %v", err)
}
defer strm.Close()
// Read everything from the stream
receivedContents, err := ioutil.ReadAll(strm)
if err != nil {
return fmt.Errorf("could not read object: %v", err)
}
fmt.Println("\n\nRecievd data")
fmt.Println(string(receivedContents))
return nil
}
Please tell me where i am making mistake .