# How i can move a file that has been attached with widget?

**URL:** <https://community.ofelia.com/t/how-i-can-move-a-file-that-has-been-attached-with-widget/7611>\
**Category:** Q&A\
**Created:** [18 July 2016 13:41 UTC](https://community.ofelia.com/t/how-i-can-move-a-file-that-has-been-attached-with-widget/7611 "2016-07-18T13:41:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![claz08](https://avatars.discourse-cdn.com/v4/letter/c/5e9695/32.png) [@claz08](https://community.ofelia.com/u/claz08)\
**Post date:** [18 July 2016 13:41 UTC](https://community.ofelia.com/t/how-i-can-move-a-file-that-has-been-attached-with-widget/7611/1 "2016-07-18T13:41:25Z")

</div>

Hi,

I want to move a file to another folderThis file will be attached with a widget.

Now i have created a script task, and i have impelemented this code, but when i try to test, nothing works good.Here is the java code:

` import org.bonitasoft.engine.bpm.document.Document;  
import org.bonitasoft.engine.bpm.document.DocumentValue;

```
Document doc=apiAccessor.getProcessAPI().getLastDocument(processInstanceId, "attachedDoc").getId();
//Document doc=apiAccessor.getProcessAPI().getDocument(attachedDoc);
DocumentValue docValue=new DocumentValue(apiAccessor.getProcessAPI().getDocumentContent(doc.getContentStorageId()), doc.getContentMimeType(), doc.getContentFileName());
return docValue;

```

`

Regards

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [19 July 2016 23:49 UTC](https://community.ofelia.com/t/how-i-can-move-a-file-that-has-been-attached-with-widget/7611/2 "2016-07-19T23:49:36Z")

</div>

This is what you need:

But you’ll have to code it correctly as it’s not from Bonita…

`
byte[] buffer = new byte[8 * 1024];
//Set output filename
String filename = “D:/mydir/myfile.txt”
`

`//set input stream
InputStream input = urlConnect.getInputStream();
try {
OutputStream output = new FileOutputStream(filename);
try {
int bytesRead;
while ((bytesRead = input.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
} finally {
output.close();
}
} finally {
input.close();
}
`

regards  
Seán

_PS: If this reply answers your question, please mark as resolved._

---

<div class="post-metadata">

**Author:** ![chris1braun99](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@chris1braun99](https://community.ofelia.com/u/chris1braun99)\
**Post date:** [2 January 2017 16:29 UTC](https://community.ofelia.com/t/how-i-can-move-a-file-that-has-been-attached-with-widget/7611/3 "2017-01-02T16:29:00Z")

</div>

People who make use of the ADSL router these days get more benefits than users of ADSL modem. This is because all routers IP like [192.168.2.1](http://www.19216821ip.com/) in this category at this time have built-in basic firewalling elements.

---

<div class="post-metadata">

**Author:** ![chris1braun99](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@chris1braun99](https://community.ofelia.com/u/chris1braun99)\
**Post date:** [4 January 2017 21:43 UTC](https://community.ofelia.com/t/how-i-can-move-a-file-that-has-been-attached-with-widget/7611/4 "2017-01-04T21:43:29Z")

</div>

The quality of sound amongst those two types of headphones is small so pick what fits into your budget.

Read more here [BestHeadphonesUnder100.net](http://www.bestheadphonesunder100.net/)

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [19 July 2016 02:28 UTC](https://community.ofelia.com/t/how-i-can-move-a-file-that-has-been-attached-with-widget/7611/5 "2016-07-19T02:28:55Z")

</div>

A small hint here. Don’t use the “code” buttons from Bonita (as above) they don’t work as you can see,

Start code blocks with \< code \> and end with \< /code \> _removing the spaces_ and it will format the code correctly

regards  
Seán

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [19 July 2016 02:35 UTC](https://community.ofelia.com/t/how-i-can-move-a-file-that-has-been-attached-with-widget/7611/6 "2016-07-19T02:35:42Z")

</div>

**Nothing works good** is not a good question.

What is **Nothing works good**?

Where are the logs to say what is wrong?

What is it you are trying to do?

_I want to move a file to another folder. This file will be attached with a widget._

It’s not really clear, can you give an example? For example -

I need to move file **driveC://thisFile.txt** to **driveD://thisDir/thisFile.txt**

Try to be a bit clearer and the answers will be easier to calculate.

regards  
Seán

---

<div class="post-metadata">

**Author:** ![claz08](https://avatars.discourse-cdn.com/v4/letter/c/5e9695/32.png) [@claz08](https://community.ofelia.com/u/claz08)\
**Post date:** [19 July 2016 13:58 UTC](https://community.ofelia.com/t/how-i-can-move-a-file-that-has-been-attached-with-widget/7611/7 "2016-07-19T13:58:05Z")

</div>

Ok , i will explain …

I have created a form that contains a simple widget that allow to upload a file. Acording the bonita behavior, this file is converted to a binary file and afterwards is stored to bonita database. Now i have created an external PHP code that permit me to move this file to another directory(for example:c:/new\_directory), but what i’m looking for is to move it through java code into workflow without using any external script like PHP, javascript…and so on.

I hope that you understand me.

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [19 July 2016 20:15 UTC](https://community.ofelia.com/t/how-i-can-move-a-file-that-has-been-attached-with-widget/7611/8 "2016-07-19T20:15:12Z")

</div>

You want to move the document from task to task, from process to process?

Don’t move the document, just send the documentId. That’s all you need the id of the document where you need it.

For task to task in the same process is even easier, define your document at the process level (it’s the only place you can define it), and it is available to ALL tasks in the same process.

Is this what you are looking for?

regards

---

<div class="post-metadata">

**Author:** ![claz08](https://avatars.discourse-cdn.com/v4/letter/c/5e9695/32.png) [@claz08](https://community.ofelia.com/u/claz08)\
**Post date:** [19 July 2016 20:25 UTC](https://community.ofelia.com/t/how-i-can-move-a-file-that-has-been-attached-with-widget/7611/9 "2016-07-19T20:25:08Z")

</div>

No, because i need to move|copy The attached file to a simple folder on The disk.

---

<div class="post-metadata">

**Author:** ![claz08](https://avatars.discourse-cdn.com/v4/letter/c/5e9695/32.png) [@claz08](https://community.ofelia.com/u/claz08)\
**Post date:** [19 July 2016 20:25 UTC](https://community.ofelia.com/t/how-i-can-move-a-file-that-has-been-attached-with-widget/7611/10 "2016-07-19T20:25:10Z")

</div>

No, because i need to move|copy The attached file to a simple folder on The disk.
