Storj Developer Lib Upload Data

Hi…

  1. Can i upload files to storj network ,using Storj Developer library ?
  2. I am facing issue that when i upload data using Storj developer library then previous data that have been uploaded is not download by storj developer library , only recently upload data is download by Storj library , i am using same encryption phrase ?

We need to see your source to say more, but if you use the example you should know it use a hardcoded filename and it will overwrite an existing file.

Thank you so much .
How can i append data in the file ?
i am using storj library example .
Please provide example if you can .

Maybe I misunderstand you question, but you can’t change a file.

You can upload a file to a bucket, you can delete a file from bucket, and you can overwrite an existing file in a bucket, but you can’t append data to an existing file. All oparations are on filelevel not on bytelevel.

What kind of example you need? I could bring it down to the needed minimum.

Suppose i have video file of size around 1 gb can i upload that file using golang developer library ?
how should i pass data to storj Upload function ?
till now i only know to pass string data to storj library .
And thank you for your reply :grinning:

Yes you can.
Give me some time to write an example.
I came back to you in this thread.

1 Like

Here I am. I created a gist.

Thank you so much for help and for sparing some time from precious time . :smiley::smiley:

You are welcome .Is there any other question, I’m sure we’ll find someone who can help.

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 .

What error message you got?
I took the example from https://github.com/storj/storj/wiki/Libuplink-Walkthrough ](https://github.com/storj/storj/wiki/Libuplink-Walkthrough and it compiled and uploaded data. Only my download failed because “Exceeded Usage Limit”.

There is no error message . when i am uploading less data then this program is working fine ,program is creating bucket , uploading data to the bucket , downloading data from the bucket but as size of data increases program is not creating bucket (no error message , i am checking bucket http://localhost:11000/) , not uploading data (again no error ) and not downloading data (no error but i have printed value of the variable, it is blank ) . Any other way that i can check whether data is upload to storj test network (like checking any location ) ?
i have also tried to upload data in chunks but previously uploaded data is overwritten by recently uploaded data so , Only last chunk of data is available for download .
Thank you so much for running and checking code.

Sorry that it took some time to answer. Can you give me some more details to you setup? It looks like that you are using storj-sim, and I have access to a real account. I would try to clone you setup, and try to get into the same problems.

You could use the uplink binary to download the data via cli, or list the bucket content.

Yes , i am trying to upload data on storj-sim , Thank you for your help problem solved .:smiley::smiley:

A post was merged into an existing topic: Storj Developer library Connection