Last active
August 29, 2015 14:05
-
-
Save jasich/1ad1d22969cd17b79889 to your computer and use it in GitHub Desktop.
Go Chunks of Base64 Image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image := make([]byte, asset.BlobInfo.Size) | |
reader := blobstore.NewReader(ctx, asset.BlobInfo.BlobKey) | |
reader.Read(image) | |
imageAsBase64 := base64.StdEncoding.EncodeToString(image) | |
megabyte := (500) | |
totalSize := len(imageAsBase64) | |
totalChunks := int(math.Ceil(float64(totalSize) / float64(megabyte))) | |
chunks := make([]string, totalChunks) | |
for i := 0; i < totalChunks; i++ { | |
start := i * megabyte | |
offset := (start + megabyte) | |
if offset > totalSize { | |
offset = totalSize | |
} | |
chunks[i] = imageAsBase64[start:offset] | |
} | |
for i, chunk := range chunks { | |
go func(i int, chunk string) { | |
chunkURL := fmt.Sprintf("%s/%s/Data/%d/.json?auth=%s", firebaseDataURL, share.FriendlyName, i, firebaseAuthKey) | |
chunkReq, err := http.NewRequest("PUT", chunkURL, strings.NewReader("\""+chunk+"\"")) | |
if err != nil { | |
//return err | |
} | |
chunkReq.Header.Set("Content-Type", "appliction/json") | |
if _, err := client.Do(chunkReq); err != nil { | |
//return err | |
} | |
}(i, chunk) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment