Hi …
Please find the code below :
func Storj(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)
fmt.Println("Creating New Uplink Object")
var cfg uplink.Config
cfg.Volatile.TLS.SkipPeerCAWhitelist = true
upl, err := uplink.NewUplink(ctx, &cfg)
//upl, err := uplink.NewUplink(ctx, nil)
if err != nil {
return fmt.Errorf("could not create new Uplink object: %v", err)
}
defer upl.Close()
fmt.Println("Open Project ")
proj, err := upl.OpenProject(ctx, satelliteAddress, apiKey)
if err != nil {
return fmt.Errorf("could not open project: %v", err)
}
defer proj.Close()
fmt.Println("Create Bucket " ,bucketName)
_, err = proj.CreateBucket(ctx, bucketName, nil)
fmt.Println("Create Bucket " ,err)
if err != nil {
return fmt.Errorf("could not create bucket: %v", err)
}
fmt.Println("Creating new encryption ",encryptionPassphrase)
fmt.Println("List of bucket ")
list := uplink.BucketListOptions{
Direction: storj.Forward}
for {
result, err := proj.ListBuckets(ctx, &list)
if err != nil {
return err
}
for _, bucket := range result.Items {
fmt.Println("Bucket: %v\n", bucket.Name)
}
if !result.More {
break
}
list = list.NextPage(result)
}
fmt.Println("Phrase ")
encryptionKey, err := proj.SaltedKeyFromPassphrase(ctx, encryptionPassphrase)
fmt.Println("Phra errpr",err)
if err != nil {
return fmt.Errorf("could not create encryption key: %v", err)
}
access := uplink.NewEncryptionAccessWithDefaultKey(*encryptionKey)
fmt.Println("Opening created bucket",bucketName);
bucket, err := proj.OpenBucket(ctx, bucketName, access)
fmt.Println("Opening bucket",err)
if err != nil {
return fmt.Errorf("could not open bucket %q: %v", bucketName, err)
}
defer bucket.Close()
fmt.Println("Converting Data to Buffer");
buf := bytes.NewBuffer(dataToUpload)
if err != nil {
fmt.Println(err)
}
err = bucket.UploadObject(ctx, uploadPath, buf, nil)
fmt.Println("Error uploading object ",err);
if err != nil {
return fmt.Errorf("could not upload: %v", err)
}
fmt.Println("Opening bucket for downloading");
// 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()
fmt.Println("Downloading range");
// 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()
fmt.Println("Read from the stream");
// Read everything from the stream
receivedContents, err := ioutil.ReadAll(strm)
if err != nil {
return fmt.Errorf("could not read object: %v", err)
}
return nil
}
Error :
Error for storj test network (storj sim):
1) When i am creating a bucket using above code and then try to upload data in that bucket , data is not getting upload to storj test network (storj-sim) but if i create bucket using Minio web GUI (localhost:11000 ) and then run only data uploading code . Above program uploads data to the bucket but after uploading data bucket becomes inaccessible when i try to check bucket data in web based GUI (localhost:11000) , so when i click on bucket name from the sub menu (localhost:11000) page refresh and opens first bucket in the list
Error on storj network (live) :
1)When i created bucket using above code and trying to upload data then program is displaying error
Error uploading object segement error : ecclient error :
And when i am trying to upload data to the bucket (created by above program) using Uplink cli then error displayed
Fatel error : decryption failed , check encryption key
Question
- Is this error is due to encryption key ?
2)If above error is due to encryption key then how can i manage encryption key error ? - if now how can i solve this issue ?