# Upload download mp3 file to SD card

**URL:** <https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305>\
**Category:** General\
**Created:** [April 16, 2015, 12:44pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305 "2015-04-16T12:44:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhoulay](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rhoulay/32/5121_2.png) [@rhoulay](https://community.particle.io/u/rhoulay)\
**Post date:** [April 16, 2015, 12:44pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/1 "2015-04-16T12:44:43Z")

</div>

Hi, I want know how upload and download mp3 file to SD card.

Something like:

1. Send: microphone -\> music shield -\> mp3 -\> SD card -\> upload mp3 to internet server;
2. Receive: download mp3 from internet server -\> save to SD card -\> music shield -\> speaker;

Should I use HTTP POST GET or TCP?

---

<div class="post-metadata">

**Author:** ![marcus](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/marcus/32/1312_2.png) [@marcus](https://community.particle.io/u/marcus)\
**Post date:** [April 16, 2015, 1:17pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/2 "2015-04-16T13:17:31Z")

</div>

Hmm,

If you just want an mp3 file on the SD card without any programming I advise you to copy the file to the card using a PC. 😉

Other wise You are in for a lot of programming; MP3 encoding, connecting through the sd card @kennethlimcp, by means of the library written by @mdma, and so forth.

good luck!

---

<div class="post-metadata">

**Author:** ![rhoulay](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rhoulay/32/5121_2.png) [@rhoulay](https://community.particle.io/u/rhoulay)\
**Post date:** [April 16, 2015, 1:23pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/3 "2015-04-16T13:23:54Z")

</div>

The idea work like voice message: voice to mp3, and mp3 to speaker.

So I want find way send and receive mp3 file with server. I find spark core support tcp, but good send string. If I need upload and download mp3 file, I think should use something like ftp?

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [April 16, 2015, 1:30pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/4 "2015-04-16T13:30:49Z")

</div>

@rhoulay, you could use a VS1053 breakout like this one:

> **[VS1053 Codec + MicroSD Breakout - MP3/WAV/MIDI/OGG Play + Record](https://www.adafruit.com/product/1381)**
>
> This breakout board is the ultimate companion for the VLSI VS1053B DSP codec chip. The VS1053 can decode a wide variety of audio formats such as MP3, AAC, Ogg Vorbis, WMA, MIDI, FLAC, WAV ...

The use of TCP is most likely the best interface for large data though packet sizes are limited to 1400 bytes or so. The VS1053 will compress the MIC audio but I am not sure it will store it on the SD card. There is a [library](https://github.com/pkourany/Adafruit_VS1053_Library) for the VS1053 available though some members have reported issues with higher bitrates. You have your work cut out but I believe it is possible. Do a search in the Community for “VS1053” and you will find topics very similar to what you are looking for. 😃

---

<div class="post-metadata">

**Author:** ![harrisonhjones](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/harrisonhjones/32/4132_2.png) [@harrisonhjones](https://community.particle.io/u/harrisonhjones)\
**Post date:** [April 16, 2015, 6:58pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/5 "2015-04-16T18:58:18Z")

</div>

This is definitely do-able. I’ve done the same with downloading an image into flash and then displaying it on a display connected to the Core. I download over HTTP in “chunks” so all I have to do is host the image file on any normal web server. Would this work for you?

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [April 16, 2015, 7:27pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/6 "2015-04-16T19:27:24Z")

</div>

@harrisonhjones, I’d love to see that code! 😜

---

<div class="post-metadata">

**Author:** ![marcus](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/marcus/32/1312_2.png) [@marcus](https://community.particle.io/u/marcus)\
**Post date:** [April 16, 2015, 7:50pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/7 "2015-04-16T19:50:54Z")

</div>

Good one,

In sweden we don’t have this 😉

---

<div class="post-metadata">

**Author:** ![rhoulay](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rhoulay/32/5121_2.png) [@rhoulay](https://community.particle.io/u/rhoulay)\
**Post date:** [April 16, 2015, 11:34pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/8 "2015-04-16T23:34:45Z")

</div>

@harrisonhjones Yes, I think image and audio file are same thing in this case.

And how you upload and download file with HTTP?

---

<div class="post-metadata">

**Author:** ![harrisonhjones](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/harrisonhjones/32/4132_2.png) [@harrisonhjones](https://community.particle.io/u/harrisonhjones)\
**Post date:** [April 16, 2015, 11:42pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/9 "2015-04-16T23:42:22Z")

</div>

@rhoulay,@peekay123, I’ll try to package the code up and put it on a gist tomorrow. Ping me if you don’t hear anything by Saturday

---

<div class="post-metadata">

**Author:** ![rhoulay](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rhoulay/32/5121_2.png) [@rhoulay](https://community.particle.io/u/rhoulay)\
**Post date:** [April 19, 2015, 1:07am UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/10 "2015-04-19T01:07:19Z")

</div>

@harrisonhjones hi, how about your sample code?

---

<div class="post-metadata">

**Author:** ![harrisonhjones](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/harrisonhjones/32/4132_2.png) [@harrisonhjones](https://community.particle.io/u/harrisonhjones)\
**Post date:** [April 19, 2015, 1:38am UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/11 "2015-04-19T01:38:19Z")

</div>

Hey, this code is crazy rough and not all of its actually there but the general gist is there. Read through it and ask any questions if you are unclear.

> <https://gist.github.com/harrisonhjones/7f7eb97600069279e16e>

It downloads an image which is fixed @ 9600 bytes. As such, there’s only enough free space available for 80 “slots” for these images to be saved into external flash. A more flexible implementation would be nice but I simply haven’t had the time to write it.

---

<div class="post-metadata">

**Author:** ![rhoulay](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rhoulay/32/5121_2.png) [@rhoulay](https://community.particle.io/u/rhoulay)\
**Post date:** [April 20, 2015, 1:56pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/12 "2015-04-20T13:56:10Z")

</div>

Hi, @harrisonhjones I find you use some custom function and variable not include in your sample code. Could you include that code?

And how about the main setup and loop flow for spark core?

---

<div class="post-metadata">

**Author:** ![harrisonhjones](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/harrisonhjones/32/4132_2.png) [@harrisonhjones](https://community.particle.io/u/harrisonhjones)\
**Post date:** [April 20, 2015, 5:57pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/13 "2015-04-20T17:57:00Z")

</div>

Sure. Reply back which functions you need and I’ll gladly provide them. The DBG\_\* functions are just special Serial.print(…) statements which I constructed to make it easier to visualize what’s going on. You are also going to be missing a decent number of constants… I’ll just post the entire file tonight. I’ll update you when it’s there

---

<div class="post-metadata">

**Author:** ![harrisonhjones](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/harrisonhjones/32/4132_2.png) [@harrisonhjones](https://community.particle.io/u/harrisonhjones)\
**Post date:** [April 22, 2015, 5:23am UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/14 "2015-04-22T05:23:11Z")

</div>

Alright guys/gals. It’s updated: [https://gist.github.com/harrisonhjones/7f7eb97600069279e16e](https://gist.github.com/harrisonhjones/7f7eb97600069279e16e). That’s the whole thing. All that’s needed now is a web server with a script running on it (to serve the image files)

Ping @peekay123 and @rhoulay so you both see this

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [April 22, 2015, 12:10pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/15 "2015-04-22T12:10:49Z")

</div>

@harrisonhjones, thanks for sharing! My troublemaker brain is wondering if a webhook could not be used to make the image request (non-local server) and get the data back as 512-byte chunks 😜

---

<div class="post-metadata">

**Author:** ![harrisonhjones](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/harrisonhjones/32/4132_2.png) [@harrisonhjones](https://community.particle.io/u/harrisonhjones)\
**Post date:** [April 22, 2015, 2:38pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/16 "2015-04-22T14:38:55Z")

</div>

I don’t see why not. This was written before webhooks and for a battery application so I wanted to limit how much I used the spark cloud

---

<div class="post-metadata">

**Author:** ![rsteckler](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@rsteckler](https://community.particle.io/u/rsteckler)\
**Post date:** [April 23, 2015, 2:32pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/17 "2015-04-23T14:32:36Z")

</div>

Hi,  
Why the extra effort for transferring the for in chunks?

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [April 23, 2015, 2:51pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/18 "2015-04-23T14:51:25Z")

</div>

@rsteckler, cause webhooks remove all the tcp code requirements and because they’re fun! 😛

---

<div class="post-metadata">

**Author:** ![rsteckler](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@rsteckler](https://community.particle.io/u/rsteckler)\
**Post date:** [April 23, 2015, 3:04pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/19 "2015-04-23T15:04:38Z")

</div>

Sorry, I wasnt clear on my question 😄  
I’m wondering why @harrisonhjones used http chunk encoding for the downloads. It seems like extra effort to chunk up the transfer like that.

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [April 23, 2015, 3:13pm UTC](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305/20 "2015-04-23T15:13:54Z")

</div>

@rsteckler, both the firmware and CC3000 have limited buffering space so chunking avoids buffer overflow issues, which on the CC3000 causes it to crash.

[Next page](https://community.particle.io/t/upload-download-mp3-file-to-sd-card/11305.md?page=2)
