Re: improve documentation for UploadedFilesAware
Greg Huber <[email protected]>
| Newsgroups | gmane.comp.jakarta.struts.devel |
|---|---|
| Message-ID | <[email protected]> |
Rechecking these :
Could not see the link from from the interceptor pages to these detailed
help pages. Add a link after Examples?
File Upload Interceptor
Parameters
Extending the Interceptor
Examples
Or at the bottom of the page?
#####
There is a UploadedFile is a raw type. References to generic type
UploadedFile<T> should be parameterized warning
private List<UploadedFile> uploadedFiles = new ArrayList<>();
private List<UploadedFile<File>> uploadedFiles = new ArrayList<>();
|@Override public void withUploadedFiles(List<UploadedFile> uploads) { }|
@Override public void withUploadedFiles(List<UploadedFile<File>> arg0) { }
On 17/03/2024 16:46, Lukasz Lenart wrote:
> Added :) Also adjusted the Showcasehttps://github.com/apache/struts/pull/895
>
> niedz., 17 mar 2024 o 12:29 Greg Huber<[email protected]> napisał(a):
>> Looks good, but what happened to the examples with the stream stuff?
>>
>> Something like this for MultipleFileUploadUsingArrayActionusing arrays
>> example?
>>
>>
>> public class MultipleFileUploadUsingArrayAction extends ActionSupport
>> implements UploadedFilesAware {
>>
>> private List<UploadedFile<File>> uploads = null;
>>
>> public String upload() throws Exception {
>> System.out.println("\n\n upload2");
>> System.out.println("files:");
>>
>> for (UploadedFile<File> uploadedFile : this.uploads) {
>> System.out.println("*** " + uploadedFile.getOriginalName()
>> + "\t"
>> + uploadedFile.getContentType() + "\t"
>> + uploadedFile.length());
>> }
>> System.out.println("filenames:");
>> String[] uploadFileNames = getUploadedFilesFileNames();
>> for (String n : uploadFileNames) {
>> System.out.println("*** " + n);
>> }
>> System.out.println("content types:");
>> String[] uploadContentTypes = getUploadedFilesContentType();
>> for (String c : uploadContentTypes) {
>> System.out.println("*** " + c);
>> }
>> System.out.println("\n\n");
>> return SUCCESS;
>> }
>>
>> @Override
>> public void withUploadedFiles(List<UploadedFile<File>> uploadedFiles) {
>> this.uploads = uploadedFiles;
>> }
>>
>> private String[] getUploadedFilesFileNames() {
>> return this.uploads.stream().map(UploadedFile::getOriginalName)
>> .toArray(size -> new String[size]);
>> }
>>
>> private String[] getUploadedFilesContentType() {
>> return this.uploads.stream().map(UploadedFile::getContentType)
>> .toArray(size -> new String[size]);
>> }
>> }
>>
>>
>> On 17/03/2024 09:33, Lukasz Lenart wrote:
>>> Better?
>>> https://struts.staged.apache.org/core-developers/action-file-upload
>>> https://struts.staged.apache.org/core-developers/file-upload
>>>
>>> czw., 14 mar 2024 o 15:29 Greg Huber<[email protected]> napisał(a):
>>>> Sorry, I meant we need to copy/duplicate this page :
>>>>
>>>> https://struts.apache.org/core-developers/file-upload.html
>>>>
>>>> to an *action* version:
>>>>
>>>> https://struts.apache.org/core-developers/action-file-upload.html
>>>>
>>>> and modify it for the new interceptor methods/logic
>>>>
>>>> On Thu, 14 Mar 2024 at 12:42, Łukasz Lenart<[email protected]> wrote:
>>>>
>>>>> Done
>>>>> https://github.com/apache/struts-site/pull/231
>>>>>
>>>>> czw., 14 mar 2024 o 11:35 Greg Huber<[email protected]> napisał(a):
>>>>>> There is a really good page for the old upload
>>>>>>
>>>>>> https://struts.apache.org/core-developers/file-upload.html
>>>>>>
>>>>>> But the << back to Core Developers Guide does not make it easy to find
>>>>>> it again.
>>>>>>
>>>>>> ##
>>>>>>
>>>>>> https://struts.apache.org/core-developers/action-file-upload-interceptor
>>>>>>
>>>>>> would benefit a similar detail page, updated and with the stream stuff.
>>>>>>
>>>>>> return
>>>>> this.uploadedFiles.stream().map(UploadedFile::getContentType).toArray();
>>>>>> otherwise without streams
>>>>>>
>>>>>> List<UploadedFile<File>>uploads =this.uploadedFiles;
>>>>>>
>>>>>> if(uploads !=null&&uploads.size()>0){
>>>>>>
>>>>>> for(inti =0;i <uploads.size();i++){
>>>>>>
>>>>>> String file uploads.get(i).getOriginalName();
>>>>>>
>>>>>> // destroy the temporary file created
>>>>>>
>>>>>> uploads.get(i).delete();
>>>>>>
>>>>>> }
>>>>>>
>>>>>> }
>>>>>>
>>>>>> On 12/03/2024 19:48, Lukasz Lenart wrote:
>>>>>>> pon., 26 lut 2024 o 12:08 Greg Huber<[email protected]> napisał(a):
>>>>>>>> The documentation only lists one file
>>>>>>>>
>>>>>>>> |public void withUploadedFiles(List<UploadedFile> uploadedFiles) { if
>>>>>>>> (!uploadedFiles.isEmpty()) { this.uploadedFile = uploadedFiles.get(0);
>>>>>>>> this.fileName = uploadedFile.getName(); this.contentType =
>>>>>>>> uploadedFile.getContentType(); this.originalName =
>>>>>>>> uploadedFile.getOriginalName(); } }|
>>>>>>>>
>>>>>>>> For multiple files these need populating
>>>>>>>>
>>>>>>>> privateFile[]uploadedFiles=null;
>>>>>>>>
>>>>>>>> privateString[]uploadedFilesContentType=null;
>>>>>>>>
>>>>>>>> privateString[]uploadedFilesFileName=null;
>>>>>>>>
>>>>>>>> We have to loop and do it ourselves now?
>>>>>>> Basically it would be better to stop using additional fields if not
>>>>>>> needed. You can achieve the same behaviour just exposing getters
>>>>>>> extracting what's needed from "uploadedFiles", eg:
>>>>>>>
>>>>>>> public void withUploadedFiles(List<UploadedFile> uploadedFiles) {
>>>>>>> this.uploadedFiles = uploadedFiles;
>>>>>>> }
>>>>>>>
>>>>>>> public String[] getUploadedFilesContentType() {
>>>>>>> return
>>>>> this.uploadedFiles.stream().map(UploadedFile::getContentType).toArray();
>>>>>>> }
>>>>>>>
>>>>>>> etc.
>>>>>>>
>>>>>>>
>>>>>>> Cheers
>>>>>>> Lukasz
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe,e-mail:[email protected]
>>>>>>> For additional commands,e-mail:[email protected]
>>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe,e-mail:[email protected]
>>>>> For additional commands,e-mail:[email protected]
>>>>>
>>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe,e-mail:[email protected]
>>> For additional commands,e-mail:[email protected]
>>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:[email protected]
> For additional commands, e-mail:[email protected]
>